locked
SqlException: Login failed for user 'id'. RRS feed

  • Question

  • Hello there

    I am not able make database connectivity  using web services  here is the code...in which i am passing

    server=.;uid=sa;pwd=;database=Northwind;  as parameter

     

    [WebMethod]

    public DataSet ParaDBConnectivity(String server1, String id , String pw, String db)

    {

    SqlConnection con = new SqlConnection("Server=.; uid=id; pwd=pw; database=db");

    SqlDataAdapter da = new SqlDataAdapter("select * from Customers",con);

    DataSet ds= new DataSet();

    da.Fill(ds,"C");

    return ds;

    }

     

     

    The Error which i am getting is......

     

    System.Data.SqlClient.SqlException: Login failed for user 'id'.
       at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
       at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState)
       at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
       at WebService2.FirstService1.ParaDBConnectivity(String server1, String id, String pw, String db) in c:\inetpub\wwwroot\webservice2\firstservice1.asmx.cs:line 84
    
    Thursday, June 21, 2007 11:02 AM

All replies

  • You are literally passing the string "server=.;uid=id;pwd=pw;database=db".  I see you have parameters server1, id, pw, and db.  I imagine you hardcoded the server in this string just to get this far, but you need to construct your string from your parameters.  Something like:

     

    String connstr = "Server="+server1+"; uid="+id+";pwd="+pw+";database="+db;

     

    SqlConnection con = new SqlConnection(connstr);

     

    or the like.

     

    In this context, your parameters are not being used.

     

    Hope this helps,

     

    John (MSFT)

    Thursday, June 21, 2007 6:40 PM
  • I am guessing that you are coming from an ODBC background, because you are passing ODBC connection string parameters.

     

    Try the following:

     

    using(SqlConnection connection = new SqlConnection(data source=localhost;Initial Catalog=db;User ID=id;Password=pw)) {

     

            connection.Open();

            .

            .

            .

            connection.Close();

     

    }

     

    www.connectionstrings.com

    Tuesday, June 26, 2007 10:39 PM