简体   繁体   中英

Creating a custom installer for occasionally connected application using database of another software

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..ie 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?

  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;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM