【问题标题】:Sql Server 2008 R2 Express LocalDB/ v11.0 connectivity issuesSql Server 2008 R2 Express LocalDB/ v11.0 连接问题
【发布时间】:2014-10-28 08:58:38
【问题描述】:

我有一个使用本地数据库(服务数据库)“.mdf”文件的 Windows 窗体应用程序。我可以使用下面的连接字符串从开发机器连接到这个数据库。

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

仅当我尝试在另一台机器上安装时才会出现此错误。我不确定我错过了什么?

【问题讨论】:

  • 确保(SQL Server Browser 服务)正在运行并且所需的 TCP 端口已打开。
  • @Lolo 我感谢您的回复。我发现Sql server Browser服务正在运行,并且TCP端口是开放的。
  • 在您要安装的机器上?
  • 是的。它已经启动并运行了所有这些。我什至也尝试过重启机器。
  • 当我将它安装在开发机器上时,它可以完美运行。

标签: sql .net sql-server vb.net winforms


【解决方案1】:

我们已经部署了一个 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;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多