I am facing a strange problem. I have pre compiled project which was running fine . Now I am trying to run the same project it is giving me following error: Server Error in '/MTLC' Application. --------------------------------------------------------------------------------
Cannot open database "MTLC" requested by the login. The login failed. Login failed for user 'RITU-PC\Administrator'. 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 "MTLC" requested by the login. The login failed. Login failed for user 'RITU-PC\Administrator'. 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 "MTLC" requested
by the login. The login failed. Login failed for user 'RITU-PC\Administrator'.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849015 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj) +194 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean
enlistOK) +35 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String
host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString
connectionOptions, String newPassword, Boolean redirectedUserInstance) +221 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection
owningObject, Boolean redirectedUserInstance) +189 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection
owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject) +499 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117 System.Data.SqlClient.SqlConnection.Open()
+122 _Default.btnLogin_Click(Object sender, EventArgs e) +108 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,
Boolean includeStagesAfterAsyncPoint) +1565 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.4971; ASP.NET Version:2.0.50727.4971 I attached .mdf file in database.
When I am taking a grid view and selecting any table with sqlDataSource it is populating data properly.With the same connection string, while I am running project it is giving me above error. What Should I do? I am using VS2008,win 7 with Administrator account.
Thanks all for your replies. I solved it myself. It was security problem. I the database file(.mdf) was not given sufficient permission to the current user.
Thanks again.
Marked as answer by Allen Li - MSFT on Jun 28, 2012 02:04 AM
mishra.bhupe...
Participant
1598 Points
378 Posts
DataBase Connection
Jun 22, 2012 03:04 PM|LINK
Honnappa
Participant
1112 Points
534 Posts
Re: DataBase Connection
Jun 22, 2012 03:11 PM|LINK
Can you recheck the connectionstring?
My Profile
mishra.bhupe...
Participant
1598 Points
378 Posts
Re: DataBase Connection
Jun 22, 2012 03:32 PM|LINK
Honnappa
Thanks for reply:
Previous connection string:
<add name="MTLCConnectionString" connectionString="Data Source=.\SQLExpress;Initial Catalog=MTLC;Integrated Security=True"
providerName="System.Data.SqlClient" />
New Connection string that I got from SqlDataSource's configuration:
<add name="MTLCConnectionString" connectionString="Data Source=RITU-PC\SQLEXPRESS;Initial Catalog="F:\FINAL PROJECT(MTLC)\MTLC\MTLC.MDF";Integrated Security=True"
providerName="System.Data.SqlClient" />
Both giving same error. But when I am opening it in Management Studio( SSMS) working properly or in gridView it is showing all data.
FightAsABull
Contributor
2228 Points
424 Posts
Re: DataBase Connection
Jun 27, 2012 07:57 AM|LINK
This will help:
http://msdn.microsoft.com/en-us/library/bf7sd233.aspx
Honnappa
Participant
1112 Points
534 Posts
Re: DataBase Connection
Jun 27, 2012 08:31 AM|LINK
did you provode database credentials in ur connectionstring?
Use server authentication and try this
Database==>Security==>Users==> create a user with password
My Profile
mishra.bhupe...
Participant
1598 Points
378 Posts
Re: DataBase Connection
Jun 27, 2012 08:35 AM|LINK
Thanks all for your replies. I solved it myself. It was security problem. I the database file(.mdf) was not given sufficient permission to the current user.
Thanks again.