1

I have a C# windows forms application and it works with Sql Server Express on my own machine. I have published my program with release.exe file and included there the Script.sql file in order to have the database of the program. The program works perfectly in my machine because I have the database and SQL server. On other machine that has an SQL server, also working perfectly, but that machine must run(execute) the Script.sql file with DBMS first and than it works.

This is my connection string: connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Assessment;Integrated Security=True;

So the issue is: I cannot use my program on the machine that has not installed SQL Server.

Question: Is it possible to run my program with database on the other machine that has not installed SQL Server and Visual Studio at all?

I heard that, If I add some .dll files or the .mfd/.ldf files to the project, it's possible to run the program without SQL Server.

I know that I'm using the database in a complicated way(including Script.sql and running it manually) cuz I'm beginner in programming. Sorry if I'm asking a stupid question...

Thank you!

Abdullokh
  • 47
  • 2
  • 9
  • StackOverflow is not a code writing service. If you have a problem with your code, please provide Minimal, Complete, and Verifiable example. – Shubham Verma Feb 14 '17 at 06:42

3 Answers3

2

So you are trying to run your application on a machine that has neither SQL Express nor SQL Standard/Enterprise installed. If you want to stick with Microsoft SQL technology and you want to avoid shipping the full SQL Express installer with your application, then you will need to use SQL Express LocalDB. Here is a link to it: https://msdn.microsoft.com/en-us/library/hh510202.aspx

Essentially, it is a much smaller Express version (free, 10GB limit, etc.). You can either install it with your application's installer, or have your application check on first start-up if a SQL Server is available (if not, install and use LocalDB). It does have a few limitations that might make it a great option or not:

  • No connections to the database from outside of the machine (therefore the name, LocalDB). This way you have less to worry about security.
  • Depending on how you create the DB instance, the SQL process will automatically shut down when your app stops, and not continue consuming resources on the machine.

The MSDN article talks about developers. However, LocalDB is perfectly suitable for production use, as kind of embedded database.

If this looks like an option to you, please don't forget to mark this as the answer to your question.

Christoph
  • 2,211
  • 1
  • 16
  • 28
1

You can host a web service in a server where the service will fetch the data from the database. All your winform application has to do is just call the service methods and it'll get data accordingly. In this way, you need not to worry about having MSSQL in the client PC at all.

The idea might seem a bit difficult for you as you're a beginner programmer, but this is a widely followed architecture and you can start trying to implement it.

Abdur Rahman
  • 657
  • 16
  • 46
Rashik Hasnat
  • 318
  • 4
  • 14
-1

Try this

   private void button1_Click(object sender, EventArgs e)
    {
        DataTable dtCPData = new DataTable();
        string sqlconstr = "Data Source=dbhost;Initial Catalog=dbname;Persist Security Info=True;User ID=username;Password=password";

        SqlConnection con = new SqlConnection();
        con.ConnectionString = sqlconstr;
        con.Open();
        SqlCommand cmd = new SqlCommand(@"Select * from Table", con);

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dtCPData);
        con.Close();

    }
Rahul
  • 199
  • 8