使用TCP/IP&连接到sql服务器港口 [英] Connect to sql server with TCP/IP & Port
本文介绍了使用TCP/IP&连接到sql服务器港口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我的朋友们!
我的联系方式是:
hello
my friends !
my connection strin is :
string strConnection;
strConnection = "Data Source=192.168.2.107,8484;Network
Library=DBMSSOCN;Initial Catalog=test;UID=sa;pwd=";
SqlConnection connDB = new SqlConnection(strConnection);
connDB.Open();
1-tcp/ip已启用
2 ping可以
在防火墙中添加了3端口
请帮帮我!
但是,错误:
1-tcp/ip is enable
2-ping is ok
3-port in firewall is added
please, help me!
but , error :
System.Data.SqlClient.SqlException: Login failed
for user 'sa'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject stateObj)
at
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean
enlistOK)
at
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo
serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64
timerExpire, SqlConnection owningObject)
at
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String
host, String newPassword, Boolean redirectedUserInstance, SqlConnection
owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection
owningObject, 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 WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs
e) in D:\Hesam\ConnectTCP_WIN\ConnectTCP_WIN\Form1.cs:line
35
推荐答案
System.Data.SqlClient.SqlException: Login failed
for user ''sa''.
如您所见,我的错误是您的用户名和密码,请确保所提供的内容在服务器上有效.
另外 Connectionstrings.com [ ^ ]是这类故障排除的好资源
As you can see from what I have higlighted the error is your username and password make sure what you have supplied is valid on the server.
Also Connectionstrings.com[^] is a great resource for these sort of moments of troubleshooting
我不知道这是否会有所帮助,但这是我每次连接到SQL Server 2005数据库时都会使用的代码:
I dnt know if this one will help, but this code is the code i use everytime i connect to my SQL Server 2005 Database :
Public Sub ConnectDatabase(db As String)
'Provider=SQLNCLI.1;Integrated Security=SSPI;Persist Security
'Info=False;Initial Catalog=Counts2;Data Source=D-OF-MSSQM-0302
'Disconnect
Set conn = New ADODB.Connection
With conn
.CursorLocation = adUseServer
.ConnectionTimeout = 25
.CommandTimeout = 0
.Provider = "SQLNCLI.1"
.Properties("Data Source").Value = "D-OF-MSSQM-0302" '--server name
.Properties("Integrated Security").Value = "SSPI"
.Open
.DefaultDatabase = db
End With
End Sub
尝试创建另一个用户并在连接字符串中使用这些凭据.
我知道这并不能直接解决您的问题,但似乎是调试问题的下一步.
Try to create another user and use those credientials in the connection string.
I know this doesn''t directly solve your problem, but seems like a logical next step in debugging your problem.
这篇关于使用TCP/IP&连接到sql服务器港口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文