【问题标题】:Office network SQLEXPRESS - Connecting Winform issue办公网络 SQLEXPRESS - 连接 Winform 问题
【发布时间】:2011-11-18 15:19:09
【问题描述】:

我创建了一个 Winform,它使用受信任的连接字符串连接到 SQL Server Express x64。

在开发机器上(也运行 SQL Server)Winform 工作 100%,生成的连接字符串是:

Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=.\SQLEXPRESS

当我在联网的 PC 上尝试相同的 win 表单时,它无法连接。在远程机器上,我可以通过网络看到开发机器,即\\JOHN-WIN7PC

远程 PC 的结果连接字符串是:

Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=\\JOHN-WIN7PC\SQLEXPRESS

我还在 SQL Server 上启用了 TCP-IP(它被设置为 <default>),关闭了所有防火墙、反恶意软件(这应该不会干扰)并且两台机器上都没有安装反病毒软件。

SQL database settings are as follows:
==================================================
Authentication method: Windows Authentication
Database: BushBreaksLodgeManager
ServerName: JOHN-WIN7PC\SQLEXPRESS
Instancename: SQLEXPRESS
Computername: JOHN-WIN7PC

Sql Server settings
==================================================
Mixed mode (Win auth and Sql Server)
Connections -> Allow remote connections = true

在这方面的任何帮助将不胜感激,因为我不知所措。

我在下面粘贴了异常:

2011/11/18 04:55:50 PM : Process: UtilsDatabase -> TestDatabaseConnection
2011/11/18 04:56:05 PM : Process: UtilsDatabase -> TestDatabaseConnection Connection failed
2011/11/18 04:56:05 PM : Settings value -> UseIntergratedSecurity: False
2011/11/18 04:56:05 PM : Settings value -> Server: \\JOHN-WIN7PC\SQLEXPRESS
2011/11/18 04:56:05 PM : Settings value -> Database name: BushBreaksLodgeManager
2011/11/18 04:56:05 PM : Connection String: Persist Security Info=False;Integrated Security=true;Initial Catalog=BushBreaksLodgeManager;server=\\JOHN-WIN7PC\SQLEXPRESS

==================== New Exception ====================
2011/11/18 04:56:05 PM

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: 25 - Connection string is not valid)

.Net SqlClient Data Provider

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at BushBreaksLodgeManager.UtilsDatabase.TestDatabaseConnection()

Void OnError(System.Data.SqlClient.SqlException, Boolean)

【问题讨论】:

  • 这是在域环境中吗?运行远程软件的用户是否已创建为服务器上的登录名/用户?
  • 这是 2008 版还是 2005 版?我记得在 Express 2005 中,您必须明确告诉它接受远程连接。不知道 2008 和 2008R2 版本的情况如何。
  • 不,它纯粹是在一个办公室内。不需要安全性,因此是受信任的连接字符串。他们没有要求任何详细的信息。只需提供数据库名称和sql server 路径和服务器名称即可连接到服务器。
  • 这是 Sql Server 2008 R2 64 位
  • “受信任的连接”和“集成安全性”旨在在网络上的所有用户和服务器本身都属于同一个(或受信任的)Windows 域(它是活动的)的情况下工作-directory 验证了“受信任”的域凭据),但在您的情况下,您似乎在工作组中。我记得如果您在服务器上使用与工作组用户相同的凭据重新创建相同的用户帐户,您可以使用工作组,但这很难开始工作。也许切换到 sql 身份验证并以这种方式创建用户会更简单。

标签: winforms sql-server-express sql-server-2008r2-express


【解决方案1】:

我认为错误很简单。连接到 SQL Server 时,您不要在服务器名称前加上 \\,因此您应该使用 server=JOHN-WIN7PC\SQLEXPRESS 而不是 server=\\JOHN-WIN7PC\SQLEXPRESS

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-04
    • 2011-07-24
    • 2019-02-07
    • 2020-07-08
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多