Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello
my friends !

my connection strin is :
C#
                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 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
Posted

System.Data.SqlClient.SqlException: Login failed 
for user 'sa'.


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
 
Share this answer
 
v2
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 :

VB
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
 
Share this answer
 
v2
Comments
Simon_Whale 17-Aug-11 12:05pm    
Added <pre lang="vb"> ...code here... </pre> to make code easily ready
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.
 
Share this answer
 
v2
As the error says, the password for user sa is wrong. Another thing to check is that you have mixed mode authentication on. If only windows authentication is on, you have to use trusted security.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900