配置连接字符串到SQL Server Express以使用每个计算机/服务器名称

时间:2015-09-11 15:00:26

标签: sql-server connection-string sql-server-express sql-server-2012-express

如何配置我的SQL Server Express连接字符串,服务器属性接受运行SQL Server的计算机名称,即当前计算机:

<connectionStrings>
    <add name="MyDbConn1" 
         connectionString="Server=.\SQLEXPRESS;Database=MyDb;Trusted_Connection=Yes;"/>       
</connectionStrings>

我在某处看到过如上所述的配置,其中server属性具有.\SQLEXPRESS值。

点符号是什么意思?

1 个答案:

答案 0 :(得分:0)

<connectionStrings>
  <add name="MyDbConn1" connectionString="Server=localhost;Database=MyDb;Trusted_Connection=Yes;"/>       
</connectionStrings>

If it is a named instance with a different name than "SQLEXPRESS" or the SQL instance is exposed on a port other than 1433, you will have to change that in the connection string as well. Typically, if there is only one SQL instance, Server=localhost will totally suffice.

Does it not work, simply by referencing localhost or 127.0.0.1.

If not, you may have to go to SQL Server Configuration Manager, navigate to TCP/IP, click the IP addresses tab and enable 127.0.0.1.

Also, I think it is Trusted Connection=True not Trusted Connection=Yes, but maybe that works...?