0

I am trying to create an application which will synchronize its database with another software's database..

Problems are:

  1. How will the database will synchronize with external database after I have created the installer and installed..i.e. how will it take the connection string.

    I am looking for a solution which will provide a button to select the required database and based on the selection automatically generate the connection string.

  2. Is it possible to run SQL create queries on external database while installation after the database is selected via browse button?

Community
  • 1
  • 1
humorousdragon
  • 55
  • 2
  • 12
  • 1
    ***SQL*** is just the *Structured Query Language* - a language used by many database systems, but not a a database product... more advanced features are often highly vendor-specific - so we really need to know what **database system** (and which version) you're using.... – marc_s Jan 28 '13 at 05:43
  • other software is using sql server 2005 express version.. and i am not allowed to change it to any other, as after changing it to 2008 server express the software will refuse to recognize it. – humorousdragon Jan 28 '13 at 07:05

1 Answers1

0
  1. You have an option to create a Connection Settings form, which will help user to construct the connection string.

  2. Yes, it's possible. It looks something like this:

    using (var sqlConnection = new SqlConnection(@"Data Source=myServerAddress;User Id=myUsername;Password=myPassword;"))
    {
        sqlConnection.Open();
        string query = "CREATE DATABASE...";
        using (var sqlCommand = new SqlCommand())
        {
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = query;
            sqlCommand.ExecuteNonQuery();
        }
    }
    

If it won't work, try to set Initial Catalog to master:

@"Data Source=myServerAddress;Initial Catalog=master;User Id=myUsername;Password=myPassword;"
Michael Celey
  • 12,645
  • 6
  • 57
  • 62
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162