I'm running a simple login application locally with SQLExpress. If I run it straight out of VS2005 it will allow the user to login successfully, however if I run it through IIS it gives me the following error.
Server Error in '/BasicReview' Application.
An attempt to attach an auto-named database for file C:\Documents and Settings\jmfoster\My Documents\Visual Studio 2005\Projects\BasicReview\BasicReview\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
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: An attempt to attach an auto-named database for file C:\Documents and Settings\jmfoster\My Documents\Visual Studio 2005\Projects\BasicReview\BasicReview\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
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): An attempt to attach an auto-named database for file C:\Documents and Settings\jmfoster\My Documents\Visual Studio 2005\Projects\BasicReview\BasicReview\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739123 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +170 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +349 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.SqlClient.SqlConnection.Open() +111 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +84 System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +197 System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +1121 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105 System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42 System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +83 System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +160 System.Web.UI.WebControls.Login.AttemptLogin() +105 System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +99 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35 System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832
User instances of SQL Server Express only allow 1 open connection to the database at a time. You'll have to close the connection to the database in VS 2005 before IIS will be able to connect. Open the Data Connections panel, right-click on the database, and click "Disconnect..."
|||I've closed the connection, closed VS2005 and it still gives me the same error. I'm thinking windows security or sql security is the issue, but I'm not sure.
|||Out of curiousity, do you have a machine instance (through SQL Express Manager) of a database by the same name?
|||Is this website in a hosted site, where someone else could have the same SQL Server name?
|||I installed SQL Express Manager however I was unable to attach the database. For some reason when I try to attach databases the folder view to find it won't allow me to go very deep into the folder tree. However it does show up if in SQL Express Manager if I have VS2005 running and the database attached in there.
I have no other databases on this computer. I just installed everything a couple days ago.
|||I have a feeling that when you attempted to attach it to the SQL Express manager it may have mucked something up. Try changing the name of the mdb file and update your connection string.
|||I renamed it but receive the same error.
Let me explain what I'm doing. I'm making a very simple login app. I literally have done very little so far. In VS2005 I went to the 'Project Menu' and clicked 'ASP.NET Configuration' which allowed me to make roles and users. This step created the default database ASPNETDB.MDB in the App_Data folder in the directory of my project. My project is in the default directory for new projects (My Documents\Visual Studio 2005\Projects\BasicReview\BasicReview\App_Data).
I am able to connect to this database within VS2005, and also with SQL Express Manager (only if I have VS2005 attached to the database).
The login is successful within VS2005 ASP.NET Development runtime. However I need to use IIS. I have IIS 6 installed locally and a virtual directory set within the Defaul Website. I can see the Default.aspx page, but once I try to login it fails and displays the above error.
|||Would someone be willing to list the steps they take to get a login page working on their local machine with IIS and SQL Express? This bump in my road is killing me, I can't understand why something that everyone must do at some point in time would be so difficult.
|||Since you need to open your site using IIS as opposed to VS2005 web server you will need to attach your database (mdf file) in SQL Express Managment studio. You can do this by opening SQL Exp. Managment, and right clicking on your database and choosing attach.
Then you need to remove your connection string in your web.config and add a new one like
<add name="connection string name" connectionString="Data Source=yourservername;Initial Catalog=databasename;Integrated Security=True"
providerName="System.Data.SqlClient" />
Couple of things to keep in mind about this. By default SQLExpress uses named pipes for client connections. Which will break through IIS connections. You will also need to open up your SQL2005 Configuration Manager and configure TCP/IP for client connections. Also this will break the DB so you can't use it inside of Visual Studio anymore, you'll have to use SQL Express Management Studio to manage your DB.
No comments:
Post a Comment