Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Express 2008 using (local) in connection string

Is it possible to connect to a SQL Server Express 2008 database in ASP.NET with a server name of (local) like "server=(local);integrated security=SSPI;database=DBNAME"?

I'm working with another developer on a project and it's getting annoying having to have 2 different version of web.config because he is using SQL Server 2008 and (local) works, but I can't seem to get it to work with SQL Server 2008 Express locally.

The database is located on the same computer as the .NET code in case that matters.

Thanks.

like image 423
Jeff Treuting Avatar asked May 18 '10 00:05

Jeff Treuting


People also ask

How do I get LocalDB connection string?

Start LocalDB and connect to LocalDB To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1. mdf .


2 Answers

Assuming you both have SQL Express installed with the default instance name "SQLEXPRESS", you can have 1 connection string like:

server=.\SQLEXPRESS;integrated security=SSPI;database=DBNAME

The "." in the connection string is used to represent the local machine.

like image 87
Wallace Breza Avatar answered Oct 01 '22 10:10

Wallace Breza


You can use the SQL Server Configuration Manager tool to create an alias. Give the alias the same name on both your machine, and then you can just reference the alias in your configuration files.

I don't know if the Configuration Manager tool is actually included with the Express version of SQL Server, but if not then you can just use the registry key (it still works with Express editions). Just get your coworker to set up the alias and then export the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo

You can then import that key on your local computer. Things are slightly more complicated if you're on 64-bit Windows (because you have to set up the alias in both the 64-bit and 32-bit registry).

like image 44
Dean Harding Avatar answered Oct 01 '22 12:10

Dean Harding