0

I am trying to make a SQL form app that works offline with visual studio (c# and SQL). the build worked perfectly on my computer but not on my friend's, he already got SQL 2019 express installed another friend got it working perfectly but not this friend he keeps on getting this error i really don't know what to do anymore the only thing i understood is it is trying to load files from my pc and not his (which is why they are not found) i am really new to SQL and i feel like giving up if i cant make a build that works on other computers i dont want a server i just want something that works offline on a PC without internet

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text ************** System.Data.SqlClient.SqlException (0x80131904): The operating system returned error 5(Access is denied.) to SQL Server during a read at offset 0x00000000012000 in file 'C:\Users\G531\Desktop\New folder (3)\Database1.mdf'. Additional messages in the SQL Server error log and operating system error log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online. Could not open new database 'C:\USERS\G531\DESKTOP\NEW FOLDER (3)\DATABASE1.MDF'. CREATE DATABASE is aborted. An attempt to attach an auto-named database for file C:\Users\G531\Desktop\New folder (3)\Database1.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at TEST.Database1DataSetTableAdapters.PatientsTableAdapter.Fill(PatientsDataTable dataTable) in C:\Users\sanichi\source\repos\TEST\TEST\Database1DataSet.Designer.cs:line 6185 ---------------------------------------- System.EnterpriseServices Assembly Version: 4.0.0.0 Win32 Version: 4.8.4084.0 built by: NET48REL1 CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll


************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

jarlh
  • 42,561
  • 8
  • 45
  • 63
meowthuwu
  • 9
  • 1
  • 1
    _" i just want something that works offline on a PC without internet"_ does it _have to_ be MS SQL then? Why not use SQLite? But anyway... What's the connection string and is it hard coded or in a settings file? – Fildor Sep 07 '20 at 11:55
  • 1
    @Fildor i am really new to the whole coding thing to be honest....i picked the first one i was able to use. as for my connection string... Well i found this in the project properties """"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=False"""" i am not sure if it is the right one i've only been using it for 2 weeks – meowthuwu Sep 07 '20 at 12:01
  • _"A database with the same name exists, or specified file cannot be opened, or it is located on UNC share"_ UNC share can be ruled out, I think. But can you check if there already _is_ a database file of that name? If so, quit all instances of the program and try to just delete it. If that doesn't work rename it, then try again. – Fildor Sep 07 '20 at 12:11
  • @Fildor tried deleting and renaming it didn't work – meowthuwu Sep 07 '20 at 12:25
  • it sounds like SQL server does not have write permissions to the folder where the mdf is – WraithNath Sep 07 '20 at 14:29
  • @WraithNath is there any possible fixes ? – meowthuwu Sep 07 '20 at 14:35
  • @meowthuwu, based on the error '(Access is denied.) to SQL Server during a read at offset 0x00000000012000 in file 'C:\Users\G531\Desktop\New folder (3)\Database1.mdf''. I have two suggestions. First, you can run your app as administrator [How do I force my .NET application to run as administrator?](https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator). Second, you can move your database file to other disk such as D disk. – Jack J Jun Sep 08 '20 at 06:09
  • @meowthuwu - I wrote this post a long time ago for external drives, but you could try following it for the C drive to see if that works. https://wraithnath.blogspot.com/2016/07/set-file-permissions-so-sql-can-see.html – WraithNath Sep 08 '20 at 08:00

0 Answers0