Monday, March 19, 2012

Cannot open database "Northwind" requested by the login. The login failed............. ERR

Please, can anyone tell me why I am getting the undermentioned error message when I develop my application as an IIS Site in Visual Web Developer 2005 Express ? I have already developed and successfully tested it as a 'FileSystem Web Site' .
I am using SQLSErver Express 2005 edition and have which I have installed along with the Northwind database as per the download instructions.
My IIS software is version 5.1 which I have checked and it is configured to allow Integrated Windows Authentication.


the relevant code is
(1) web.config file connection strings

<connectionStrings>

<addname="NorthwindConnectionString"

connectionString="Data Source=.\sqlexpress;Initial Catalog=Northwind;Integrated Security=True"

providerName="System.Data.SqlClient"/>

</connectionStrings>


(2) the grid view control and sqldatasource

<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="CategoryID"

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundFieldDataField="CategoryID"HeaderText="CategoryID"InsertVisible="False"

ReadOnly="True"SortExpression="CategoryID"/>

<asp:BoundFieldDataField="CategoryName"HeaderText="CategoryName"SortExpression="CategoryName"/>

<asp:BoundFieldDataField="Description"HeaderText="Description"SortExpression="Description"/>

</Columns>

</asp:GridView>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">

</asp:SqlDataSource>


This is the full error message and details:

Server Error in '/sqlservertest' Application.

Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'JERRY-3C9615BAA\ASPNET'.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.SqlClient.SqlException: Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'JERRY-3C9615BAA\ASPNET'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[SqlException (0x80131904): Cannot open database "Northwind" requested by the login. The login failed.Login failed for user 'JERRY-3C9615BAA\ASPNET'.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +684883 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +207 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1751 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +32 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +601 System.Data.SqlClient.SqlInternalConnectionTds..ctor(SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +159 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +346 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +445 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +304 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.SqlClient.SqlConnection.Open() +111 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1837 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +129 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69 System.Web.UI.Control.EnsureChildControls() +87 System.Web.UI.Control.PreRenderRecursiveInternal() +41 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Control.PreRenderRecursiveInternal() +161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1787


Version Information: Microsoft .NET Framework Version:2.0.50215.312; ASP.NET Version:2.0.50215.312

I think you don't understand State Management in Asp.net because when you are using SQL Server your application is not a File System application. What I am saying is
SQL Server Asp.net application is not a file system application. So Asp.net is trying to connect to Northwind database in SQL Server without permissions. It is permissions
because there are two permissions in SQL Server, the server permission and the database permission. Hope this helps.

No comments:

Post a Comment