2010-10-29 52 views
0

我有一個數據庫文件在我的C:/目錄中(我也試過放在C:/ CustomerApp_C目錄中)。我可以運行該應用程序,並加載數據就好了。但是,當我改變一些數據並點擊保存時,它會出現「未處理的異常已經發生在你的應用程序中。」bla bla bla「...」更新數據庫路徑失敗「,因爲數據庫是隻讀的。C# - 更新C:/或C:/文件夾中的數據庫文件導致致命只讀文件錯誤

然後,它給了我這個在細節:

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. 

我檢查了文件屬性,所有3(文件夾,數據庫文件和數據庫日誌文件)具有隻讀的複選框選中。從邏輯上講,這使得我必須是可寫的東西......但哦,不,它不是..!

我曾嘗試以下,如在谷歌搜索建議:

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

使用這兩條線將阻止應用程序甚至顯示在屏幕上 - 儘管我已經把它的代碼後剩下的。

有沒有人有任何想法,這是怎麼回事?任何幫助將不勝感激。

順便說一句,我的用戶名(和客戶端用戶名,當這完成時)具有管理員權限。

問候,

理查德

+0

你如何連接到數據庫?你能從SSM修改數據庫嗎? – Lazarus 2010-10-29 16:22:25

+0

我假設SSM你的意思是SQL Server管理器..?我基本上有一個外部數據庫,在VS中建立一個連接,我將兩個表拖到一個DataSet中。我正在使用DataSet填充DataGridView。但是DataGridView不能改變數據庫,也不能改變連接。我可以在VS和應用程序中瀏覽數據,但不能更新它。 – ClarkeyBoy 2010-10-29 16:51:59

回答

2

如果您使用的是Windows 7的工作,你應該記住,在OS編寫到根目錄需要管理員權限(用於寫入過程)。

+0

是的,這是它...我打開了app.manifest文件,並將其更改爲最高可用。然後它要求重新啓動devenv文件,然後應用程序運行完美! – ClarkeyBoy 2010-10-29 17:40:03

0

試着右擊該文件,選擇屬性,然後選擇安全窗格。確保運行你的應用程序的用戶(可能是你自己)具有對該文件的寫入權限。

0

數據庫是否必須位於C盤或C:\創建的目錄中?另外,你正在開發哪個版本的Windows?作爲安全預防措施,更新的版本使得難以在用戶的​​Documents目錄之外創建文件。

0

假設SQL Server基於堆棧跟蹤。

嘗試:

  • 進入SQL Server Management Studio中
  • 右擊數據庫選擇
  • 屬性中選擇「選項」頁
  • 向下滾動,檢查數據庫的狀態是否是隻讀。
1

您可能沒有權限來寫C:\ 試試運行你的應用程序作爲管理員

+0

我如何將它設置爲從VS 2010執行此操作? – ClarkeyBoy 2010-10-29 16:43:13

+0

在該項目上工作時,右鍵單擊VS 2010快捷方式使用「以管理員身份運行」。在您的輸出中使用一個清單文件,指明它以admin身份運行,或者在運行時在應用上右鍵單擊「以管理員身份運行」。 – Brian 2010-10-29 17:36:03

+0

謝謝,但我通過在清單中設置請求的權限級別(或任何它)來得到它的工作。現在我真的可以完成一些事情! – ClarkeyBoy 2010-10-30 09:16:33

0

試試吧,

您Data.mdf和Data_log.ldf文件給大家,完全權限的設置安全性。

希望它解決