SQL Server Express 2008在连接字符串中使用(本地)

时间:2021-01-22 15:52:51

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"?

是否可以使用服务器名称(本地)连接到ASP.NET中的SQL Server Express 2008数据库,例如“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.

我正在与一个项目的另一个开发人员合作,因为他正在使用SQL Server 2008和(本地)工作而不得不拥有2个不同版本的web.config令人讨厌,但我似乎无法使用它来使用SQL Server 2008 Express在本地。

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

如果重要,数据库与.NET代码位于同一台计算机上。

Thanks.

2 个解决方案

#1


1  

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.

您可以使用SQL Server配置管理器工具来创建别名。在您的计算机上为别名指定相同的名称,然后您只需引用配置文件中的别名即可。

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:

我不知道配置管理器工具是否实际包含在SQL Server的Express版本中,但如果没有,那么您可以只使用注册表项(它仍适用于Express版本)。只需让您的同事设置别名,然后导出以下注册表项:

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).

然后,您可以在本地计算机上导入该密钥。如果您使用的是64位Windows(因为您必须在64位和32位注册表中设置别名),情况会稍微复杂一些。

#2


4  

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

假设您已安装SQL Express并使用默认实例名称“SQLEXPRESS”,您可以拥有1个连接字符串,如:

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

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

“。”在连接字符串中用于表示本地计算机。

#1


1  

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.

您可以使用SQL Server配置管理器工具来创建别名。在您的计算机上为别名指定相同的名称,然后您只需引用配置文件中的别名即可。

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:

我不知道配置管理器工具是否实际包含在SQL Server的Express版本中,但如果没有,那么您可以只使用注册表项(它仍适用于Express版本)。只需让您的同事设置别名,然后导出以下注册表项:

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).

然后,您可以在本地计算机上导入该密钥。如果您使用的是64位Windows(因为您必须在64位和32位注册表中设置别名),情况会稍微复杂一些。

#2


4  

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

假设您已安装SQL Express并使用默认实例名称“SQLEXPRESS”,您可以拥有1个连接字符串,如:

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

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

“。”在连接字符串中用于表示本地计算机。