Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Unable to open the physical file "D:\_Web3rev\App_Data\dbStudent.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attempt to attach an auto-named database for file D:\_Web3rev\App_Data\dbStudent.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.



i am receiving this error on my localhost everytime i accessing the local db for username and password. i have another authentication which is windows authentication for users in our intranet. i am using sql express for other users to access their data but create an error in my connection string. i tried a number of connection string but i failed.

can somebody share me his thought about this?

this is my connection string in web.config:

C#
<add name="myDbConnectionString1" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|database.mdf" providerName="System.Data.SqlClient"/>


help will be more appreciated :)
Posted

I am using DefaultAppPool application pool in my local IIS and the identity is NETWORK SERVICE. I tried creating another instance of login in another directory and it works but in this instance it failed and receiving the above error message. my windows authentication has nothing to do with this coz i tried removing it in my web.config and still the same error appears.
 
Share this answer
 
Can somebody share his comment about my topic? its a connection string to my sql database. i can explain further.


this is the true error that apppears:

C#
[SqlException (0x80131904): Unable to open the physical file "D:\_Web3rev\App_Data\database.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attempt to attach an auto-named database for file D:\_Web3rev\App_Data\dbStudent.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) +6256377
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1099
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +53
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +248
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +6271242
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +6271208
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +354
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +703
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +54
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +6272472
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +81
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1657
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +88
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6275911
   System.Data.SqlClient.SqlConnection.Open() +258
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +53
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +188
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +573
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +161
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +2790918
   System.Web.UI.WebControls.SqlDataSource.Select(DataSourceSelectArguments arguments) +31
   WebGrades.log_Click(Object sender, EventArgs e) in d:\_Web3rev\WebGrades.aspx.cs:31
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
 
Share this answer
 
v2
further:

C#
Line 29:         sds.SelectCommand = "SELECT * FROM [myTable] WHERE [username] = @username AND [password] = @password";
Line 30: 
Line 31:         DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty); -->> this is the error
Line 32:         try
Line 33:         {
 
Share this answer
 
after doing some changes in my IIS this is the error:

C#
Cannot open user default database. Login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900