views:

48

answers:

5

Hey,

I have a database file in my C:/ directory (which I have also tried putting in the C:/CustomerApp_C directory). I can run the application and it loads the data just fine. However when I change some data and click Save it comes up with "Unhandled exception has occurred in your application. bla bla bla"... "Failed to update database "path" because the database is read-only".

It then gives me this in the details:

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): Failed to update database "C:\CUSTOMERAPP_C\DATA.MDF" because the database is read-only.
   at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
   at CustomerApp.CustomerAppDS2TableAdapters.CustomerTableAdapter.Update(CustomerDataTable dataTable) in C:\Users\Clarkey\Documents\Visual Studio 2010\Projects\CustomerApp2\CustomerApp\CustomerAppDS2.Designer.cs:line 2311
   at CustomerApp.CustomerAppForm.button1_Click(Object sender, EventArgs e) in C:\Users\Clarkey\Documents\Visual Studio 2010\Projects\CustomerApp2\CustomerApp\CustomerAppForm.cs:line 123
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
CustomerApp
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Clarkey/Documents/Visual%20Studio%202010/Projects/CustomerApp2/CustomerApp/bin/Debug/CustomerApp.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Data.DataSetExtensions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/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:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

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.

I have checked the file properties and all 3 (the folder, database file and database log file) have the read-only checkbox unchecked. Logically this makes me thing it must be writable... but oh no it isnt..!

I have tried the following, as suggested in a Google search:

File.SetAttributes(@"C:\CustomerApp_C\Data.mdf", FileAttributes.Normal);
File.SetAttributes(@"C:\CustomerApp_C\Data_log.ldf", FileAttributes.Normal);

Using these two lines prevents the application from even showing on screen - even though I have put it after the rest of the code.

Does anyone have any idea as to whats going on here? Any help would be greatly appreciated.

By the way my username (and the clients username, when this is finished) has administrator permissions.

Regards,

Richard

A: 

Try right-clicking on the file, choose properties, and then choose the security pane. Make sure that the user running your app (probably yourself) has write access to the file.

klausbyskov
A: 

Does the database have to live on the C drive or a directory created in C:\? Also, which version of Windows are you developing on? More recent versions make it difficult to create files outside of the user's Documents directory as a security precaution.

Matthew Graybosch
A: 

Assuming SQL Server based on the stack trace.

Try:

  • go into SQL Server Management Studio
  • right click the database choose
  • properties select the "options" page
  • scroll down and check whether the state of the database is Read-Only.
Phil Sandler
+1  A: 

You possibly do not have permission to write it C:\ Try running your app as administrator

portland
How do I set it to do that from VS 2010?
ClarkeyBoy
Right click on the VS 2010 shortcut use "run as admin" when working on this project. Use a manifest file on your output which indicates it runs as admin, or right click "run as admin" on your app when running it.
Brian
Thanks, but I got it working just by setting the requested permission level (or whatever it is) in the manifest. Now I can actually get something done!
ClarkeyBoy
+2  A: 

If you're working on windows 7, your should remember that writing to the root directory in that OS requires administrator rights (for the writing process).

Neowizard
YES this did it... I opened the app.manifest file and changed asInvoker to highestAvailable. It then requested to restart the devenv file and then the app ran perfectly!
ClarkeyBoy