远程SQL Server连接字符串 [英] Remote SQL Server connection string

查看:196
本文介绍了远程SQL Server连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,SQL Server和发展的所有工作在本地

I have had a project where SQL Server and development all worked locally.

使用下面的连接字符串:

The following connection string was used:

  SqlConnection connection= new SqlConnection("Data Source=.\\MYDB;Initial Catalog=Database;Integrated Security=true");
  connection.Open();

我的开发团队现在越来越多,我期待有另一个开发者访问这个相同的数据库。

My development team is now growing and I am looking to have another developer access this same database.

他将需要改变这种连接字符串,我们正在努力锻炼什么的字符串中的改变 - 到目前为止,我们已经尝试:

He will need to alter this connection string and we are trying to workout what to change in the string - so far we have tried:

  SqlConnection connection= new SqlConnection("Data Source=2.221.1.145\\MYDB;Initial Catalog=Database;Integrated Security=true");
  connection.Open();

但被访问页面时被抛出以下错误:

But the following error is thrown when the page is visited:

[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)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352431
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5363103
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +922
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +518
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38

在SQL Server已启用了TCPIP协议,并侦听所有ip地址我的系统上。端口1433添加到防火墙的入站UDP和TCP和SQL Server防爆preSS实例服务已重新启动。

The SQL Server has had the TCPIP protocol enabled and is listening on all IPAddress on my system. Port 1433 is added to the firewall is inbound for UDP and TCP and the SQL Server Express instance service has been restarted.

任何人都可以请帮助我们连接字符串?此外,我觉得集成安全线将需要改变。

Can anybody please help us with the connection string? Additionally I feel the Integrated Security line will need to change.

为了简单起见,我已经动了更新的状态,以一个新的线程的问题:<一href=\"http://stackoverflow.com/questions/24541681/connection-string-for-sql-server-ex$p$pss-on-remote-computer-login-failed-error\">Connection字符串在远程计算机登录SQL Server的防爆preSS失败的错误

To keep things simple I have moved the question with the updated status to a new thread : Connection string for SQL Server Express on remote Computer login failed error

推荐答案

如果不是100%肯定它会导致错误,但是我已经看到了这行的人了,当远程连接到SQL Server的第一次,所以值得检查:

Not 100% sure if it causes that error, but I've seen this trip people up when remotely connecting to a SQL Server for the first time, so worth a check:

打开SSMS中的服务器属性,下连接,请检查允许到该服务器检查远程连接。你需要检查这从另一台机器,即使在同一个LAN连接。

Open up the server properties in SSMS, under Connections, check to see if Allow remote connections to this server is checked. You'll need that checked to connect from another machine, even if on the same LAN.

这篇关于远程SQL Server连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆