2014-05-15 159 views
0

我正在安装一个开源工具,并且在定义数据库设置时,我需要指定数据库连接字符串。他们对于SQL Server Express的连接字符串提供了一个例子如下:SQL Server 2008 R2的连接字符串与SQL Server Express的对比

Database=roadkill;Server=.\SQLEXPRESS;uid=username;pwd=password; 

但由于我使用SQL Server 2008 R2,而不是SQL Server Express的,我怎么能定义连接字符串我的SQL Server 2008 R2以同样的方式?

感谢

编辑

我尝试下面的连接字符串: -

Data Source=.\SQLExpress;Integrated Security=true; AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\roadkill.mdf 

,但我得到了以下异常: -

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 
    at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) 
    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) 
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) 
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) 
+4

这里的[的ConnectionStrings-Я美](http://www.connectionstrings.com/)网站:-) – dasblinkenlight

+0

有一个Sql Server 2008 R2的快速版。他们是(或可以)是一个一样的。 –

回答

3

连接字符串格式用于SQL Server和SQL Se rver Express是完全一样的。在这两种情况下,ServerData Source值必须是服务器和实例名称。 “。\ SQLEXPRESS”仅表示本地机器上名为“SQLEXPRESS”的实例。这是惯例,该实例名称用于SQL Server Express,但不是必需的。您可以使用不同的名称,或者可以将该名称用于完整的SQL Server实例,尽管这会导致误导。这只是一个识别标签。在所有情况下,使用“ServerName \ InstanceName”作为命名实例,而使用“ServerName”作为默认实例。您可以使用 ”。”或“(本地)”来引用本地机器。

+0

你能检查我的编辑吗? –

+0

该错误消息表明本地计算机上没有名为“SQLEXPRESS”的实例。 – jmcilhinney

+0

顺便说一句,为什么你要附加一个文件,似乎在一个位置,表明它是,或应该是,已经永久连接? – jmcilhinney

1

这两个版本的sqlserver没有区别。服务器参数的sqlexpress只有写作“.SQLEXPRESS”或说(LOCAL)两种情况的区别。

数据库= “SQLEXPRESS”
或 数据库= “(本地)”

相关问题