I checked the name from SQL Server Service Manager.Also I would like tostate here that I also tryed to establish a connection using C# and theconnection was successfully establish which means that there is noproblem with SQL Server also I sucessfully established the connectionwith MS Access and my ASP.NET application which proves that there is noproblem with IIS also.Also please check that the connection stringwhich I am providing is correct or not.The exception which I am gettingis as follows:
////////////
///////////////////////////////////////////////////////////////////
An exception occured while establishing connection
Login failed for user 'xyz\ASPNET'.
////////////////////////////////////////////////////////////////////////////
Please also note that I have a user with the name xyz/Administrator inthe logins of Sql Server 2000. Also note one more thing that the nameof my PC is xyz, I think that there is some problem with the connectionstring which i am providing so please especially check the connectionstring that either I have missed some thing or some thing has gonewrong,also please tell that are there any security restructions forASP.NET to access SQL Server 2000 or some thing like that which I haveto remove.The code is as follows:
//////////////////////////////////////////////////////////////////////////////////////
<%@. Page Language="C#" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
void Page_Load(Object sender , EventArgs e)
{
try
{
SqlConfiltered=new SqlConnection("server=xyz;Integrated Security=SSPI;database=mydatabase;");
connection.Open();
Response.Write("<b>Connection is successfully established</b>");
connection.Close();
}
catch(Exception ex)
{
Response.Write("<b>An exception occured while establishing connection</b><br>"+" "+ex.Message.ToString());
}
}
</Script
The same above code is also present in the attachement file data.aspx ,please guide me where I am making mistake and please tell me that howcan I correct this mistake so that the code executes correctly.Alsoplease tell that what things should be included in the connectionstring and also please check the connection string of this code.
Connection string is fine if you intend to use Windows Authentication against SQl Server. User xyz/Administrator being in the logins has nothing to do with the error since you probably use that when connecting to SQL Server while working with Enterprise Manager interactively (e.g you use EM)
You have specified in connection string (Integrated Security=SSPI) that the Windows Identity ASP.NET runs under will also be used to log in to the given SQL Server instance. Your ASP.NEt application runs under "'xyz\ASPNET" identity which the error message
An exception occured while establishing connection
Login failed for user 'xyz\ASPNET'.
tries to indicate. Therefore this user should have its own login created to the SQL Server and again granted access to themydatabasedatabase given in the connection string.
What you need to do is to give this user the login and adequate permissions to the SQL Server instance by using SQL Server's management tools (Enterprise Manager)
No comments:
Post a Comment