I have C# .net project with SQL Server 2008 written in Visual Studio 2008. There I used the following connection string to connect with SQL Server:
string co
Aside from LOCALHOST and "." You can
use "server = 127.0.0.1\SQLEXPRESS"
Add an alias to the SQL Server Configuration Manager and use that in your string
add 127.0.0.1 foo
to your hostsfle and use it e.g. "server = FOO\SQLExpress"
Mange the connection in the machine config
Here is a sample;
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PressbyranDB.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True
Note that Data Source=.\SQLEXPRESS;
attribute as your SQL Server and Server Instance name. Also, you do not need to restore your database from machine to machine if you use the AttachDbFilename=
attribute.
You don't have to use app config to store a connection string - you could just pass a dynamically generated connection string to the SqlConnection constructor.
If the database is local with the application you can use LocalHost
in your connection string assuming all other information is the same.
Eg:
string connectionString = @"server = LOCALHOST\SQLEXPRESS; Integrated Security = SSPI; database = XPHotelManagementDatabase";