Sunday, February 12, 2012

Cant connect to database?

When I try to connect to ms server like this:

private DataSet hentVare()
{
string sql = "select * from vare";
string strForbindelse="server=localhost;trusted_connection=true;database=mericKebab;uid=ASLAN;password=;";

SqlConnection objConnect = new SqlConnection(strForbindelse);

SqlDataAdapter dataAdapter = new SqlDataAdapter(sql,objConnect);

DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet,"Vare");

return dataSet;
}

I get this error:

System.Data.SqlClient.SqlException: Cannot open database requested in login 'mericKebab'. Login fails. Login failed for user 'ASLAN\ASPNET'.

can someone plz help me with this?Since you are using trusted SQL Server connection and the IIS virtual directory is running under the ASPNET account the application is trying to connect using that account. Try changing the IIS virtual folder to a valid domain user account that has rights on the SQL Server database you are connecting or change the authentication to SQL Server authentication and give a valid User name and password.

For more on connection strings... Visit www.ConnectionStrings.com

No comments:

Post a Comment