2014-10-28 88 views
1

我有一个Windows窗体应用程序,它利用了本地数据库(服务数据库)“密度纤维板”文件。我能够使用开发机器下面的连接字符串连接到这个数据库。SQL服务器2008 R2快速的LocalDB/11.0连接问题

<connectionStrings> 
 
    <add name="DbConnectionString" 
 
     connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MDFDb.mdf;Integrated Security=SSPI;Connect Timeout=30" 
 
     providerName="System.Data.SqlClient;Trusted_Connection=Yes;" /> 
 
    </connectionStrings>

我想现在发布应用程序。当我尝试在另一台机器上安装应用程序时。该应用程序抛出一个错误,如下所示。

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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) 
    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) 
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
    at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
    at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) 
    at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
    at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) 
    at System.Data.SqlClient.SqlConnection.Open() 
    at DataLayer.Common.DbOperations.GetDataSet(String CommandName, CommandType cmdType) 

只有当我尝试安装在不同的机器上时才会出现此错误。我不确定我缺少什么?

+0

确保(SQL Server Browser服务)正在运行并且打开了所需的TCP端口。 – Ala 2014-10-28 09:06:20

+0

@Lolo我感谢你的回复。我发现Sql server Browser服务正在运行,并且TCP端口已打开。 – user1417294 2014-10-28 09:18:18

+0

在您正在安装的机器上? – Ala 2014-10-28 09:26:43

回答

0

我们已经部署了一个WinForms应用程序,允许用户连接到任何的LocalDB/SQL Express或SQL Server的完整版本。如果选localDB我们一直在用这个连接字符串:

Data Source=(localdb)\v11.0;AttachDbFileName="C:\localdbfilename.mdf";Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False; 

我希望有帮助。它一直在为我们工作。