C # app.config file for SQL Server 2005 in VS 2008

I have a C # .net project with SQL Server 2008 written in Visual Studio 2008. There I used the following connection string to connect to SQL Server:

string connectionString = 
    @"server=HASIBPC\SQLEXPRESS; Integrated Security=SSPI; 
      database=XPHotelManagementDatabase";

But the problem is, every time I take my application from one computer to another computer, I need to change serverto connectionString. I do not want to change this manually. I want this to change dynamically. How to do this using app.config?

+3
source share
4 answers

Here is an example:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PressbyranDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True

, Data Source=.\SQLEXPRESS; SQL Server . , , AttachDbFilename=.

+2

, LocalHost , .

:

string connectionString = @"server = LOCALHOST\SQLEXPRESS; Integrated Security = SSPI; database = XPHotelManagementDatabase";
+3

- SqlConnection.

+1

LOCALHOST "."  

  • "server = 127.0.0.1\SQLEXPRESS"

  • SQL Server

  • add a 127.0.0.1 foofile to your host and use it, for example. "server = FOO \ SQLExpress"

  • Change the connection in the device configuration

0
source

Source: https://habr.com/ru/post/1760781/


All Articles