[英]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: 问题是:
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. 我正在寻找一种解决方案,该解决方案将提供一个按钮来选择所需的数据库,并根据选择自动生成连接字符串。
Is it possible to run SQL create queries on external database while installation after the database is selected via browse button? 通过浏览按钮选择数据库后,是否可以在安装时在外部数据库上运行SQL创建查询?
You have an option to create a Connection Settings form, which will help user to construct the connection string. 您可以选择创建一个“连接设置”表单,该表单将帮助用户构造连接字符串。
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: 如果它不起作用,请尝试将“初始目录”设置为master:
@"Data Source=myServerAddress;Initial Catalog=master;User Id=myUsername;Password=myPassword;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.