Winforms 办公网络SQLEXPRESS-连接Winform问题

Winforms 办公网络SQLEXPRESS-连接Winform问题,winforms,sql-server-express,sql-server-2008r2-express,Winforms,Sql Server Express,Sql Server 2008r2 Express,我创建了一个Winform,它使用可信连接字符串连接到SQL Server Express x64 在运行SQL Server的开发计算机上以及Winform 100%运行时,生成的连接字符串为: Persist Security Info=False; Integrated Security=true; Initial Catalog=BushBreaksLodgeManager; server=.\SQLEXPRESS Persist Security Info=False; Integr

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

在运行SQL Server的开发计算机上以及Winform 100%运行时,生成的连接字符串为:

Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=.\SQLEXPRESS
Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=\\JOHN-WIN7PC\SQLEXPRESS
只要我在联网PC上尝试相同的win表单,它就无法连接。在远程机器上,我可以通过网络位置(即\\JOHN-WIN7PC)看到开发机器

远程PC产生的连接字符串为:

Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=.\SQLEXPRESS
Persist Security Info=False;
Integrated Security=true;
Initial Catalog=BushBreaksLodgeManager;
server=\\JOHN-WIN7PC\SQLEXPRESS
我还启用了设置为的SQL Server上的TCP-IP,关闭了所有防火墙,并且这两台计算机上都没有安装反恶意软件

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)

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

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