Cannot open database "AdventureWorks" requested by the login. The login failed. received in web service RRS feed

  • Question

  • I have downloaded SQL Server 2005 Express addition and I am trying to connect to the Adventure Works database via a web service written in c#  using VS2005.  I can connect to the database through VS2005 and I know it is using my windows account.

    The confusion I am having is how you find out what ASPNET account is being used to access the webservice.

    I Thought it was the same as the windows account, but on reading it  uses the ANONYMOUS users...I believe, but how do you check this?
    Also how do you set the ASPNET account to have read write permissions on the ADVENTUREWORKS database?

    The database and webservice reside on the same machine.

    I have used the following code to try and connect to the database

    public string GetVendorList()


    SqlConnection sqlConn;

    XmlReader rdr;

    string ret = "";



    //Open connection to SQL Express

    string connString = @"server=.\sqlexpress;Integrated Security=SSPI;initial catalog=AdventureWorks";

    sqlConn = new SqlConnection(connString);


    //Return XML data the FOR XML AUTO clause

    string sqlString = "SELECT VendorId, AccountNumber, Name, CreditRating " +

    "FROM Purchasing.Vendor " +

    "WHERE ActiveFlag = 1 " +

    "ORDER BY Name " +

    "FOR XML AUTO ";

    SqlCommand command = new SqlCommand(sqlString, sqlConn);

    //Execute SQL query and return XML to XmlReader

    rdr = command.ExecuteXmlReader();


    while (rdr.ReadState != ReadState.EndOfFile)


    ret += rdr.ReadOuterXml();


    //Add a root element

    ret = "<vendors> " + ret + "</vendors>";




    catch (Exception ex)


    throw new Exception(ex.Message);


    return ret;


    I keep getting the following error on the sqlConn.Open();
    "Cannot open database "AdventureWorks" requested by the login. The login failed."

    I have tried to set the sa user in SQL Server Management Studio Express to public but do not really know what I am doing.  I have searched the web for 4 days now and cannot find any info for a step by step check in SQL Server Management Studio Express. 

    Any help would be great as I am a beginner to C# and to SQL Server Express.

    • Edited by fairyLiquid Tuesday, November 11, 2008 6:01 PM
    • Moved by Jenny Lo Tuesday, November 11, 2008 7:04 PM (Moved from .NET Services and SQL Data Services - On-boarding Issues to Using the Microsoft SQL Server Protocols)
    Tuesday, November 11, 2008 5:53 PM