0

I have a Windows Forms application to read, create and update members, the application is ready and I want to deploy/install it on three or four pc’s.

During the development process I have used a connection string like this:

using (SqlConnection connection = 
    new SqlConnection(
        "Data Source=MY-PC\\JGSQLSERVER;Initial Catalog=TESTSUB;Integrated Security=True"))

There is a domain on which an organisations website runs, and there is SQL server server. I have made the same table structure in the SQL web server .

My question is when I install the small windows app on any pc, do I need to change the connection address so the application can connect?

For example, like the above:

using (SqlConnection connection = 
    new SqlConnection("Data Source=web servers address\\ webSQLSERVER;Initial Catalog=TESTSUB;Integrated Security=True"))
4

3 回答 3

1

Exactly for this it is good practice to put the connection string in some kind of configuration file, either in the app.config or encrypted in some other kind of configuration. If you do this, you do not need to rebuild your app when you deploy it to different environments, or if the SQL server addresses change:

config:

<configuration>
    <connectionStrings>
      <add name="MyConnectionString" connectionString="your_connection_string" providerName="System.Data.EntityClient" />
    </connectionStrings>
</configuration>

c#:

using (SqlConnection connection = 
    new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"])){
    //do stuff
}
于 2012-12-21T07:57:37.960 回答
0

Short answer: Yes.
Otherwise your application(s) wouldn't know where to find its data(base) and would still look on the local system for it (where it couldn't be found).

于 2012-12-21T07:39:58.867 回答
0

Yes, you need to point your app to the correct server. And unless the SQL Server service is running on the same machine as your client app or in the same domain, you will most likely want to use SQL authentication, not Windows authentication. You will need to create a user in SQL Server and add it to your database, also grant it any permissions that your app requires, I guess the user is usually a DBO. Then use a different connection string:

Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

See http://www.connectionstrings.com/ for examples of various connection strings for different databases. I hope it helps.

于 2012-12-21T07:42:25.070 回答