WinForms无法更新数据库,因为该数据库是只读的 [英] WinForms Failed to update database because the database is read-only

查看:118
本文介绍了WinForms无法更新数据库,因为该数据库是只读的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在Winforms应用程序中遇到了异常.此应用程序在VS2010中运行良好,它还将跟踪信息写入到我在配置文件中配置的文件中.

当我通过安装程序安装程序部署程序时(我在V​​S2010中构建了安装项目),安装效果很好.只要您不执行任何数据库更新,该应用程序就可以正常运行-如果您这样做,则会生成上述错误.另一个提示,我的所有跟踪操作都没有按照我的配置文件写入文件.我已经完成了检查文件和文件夹未设置为READ-ONLY的常规操作.

我正在Windows7计算机上安装该程序.我怀疑该应用程序没有写文件或更新数据库的权限-我不知道如何为winform应用程序设置它-是通过app.manifest ????我对此一无所知...而且我已经浪费了数小时试图弄清楚为什么会这样.我不知道为什么我的tracelog.txt文件甚至没有生成(我在配置管理器中设置了TRACE常量)...当我通过VS2010运行它时,我的应用程序会生成很多输出,但没有一个部署和安装后的生产线.这是某种权限问题,我怎么能确定呢?在此先感谢能够提供帮助的任何人.


这是消息:

System.Data.SqlClient.SqlException:无法更新数据库"C: \ PROGRAM FILES \ PLAY \ PDMS \ DATABASE \ MEDIASLIDES.MDF因为数据库是只读的.
  在PDMS.clsApplicationFactory.Update(clsApplication应用)
  在PDMS.formApplicationSettings.buttonSave_Click(对象发送者,EventArgs e)上
  在System.Windows.Forms.Control.OnClick(EventArgs e)处
  在System.Windows.Forms.Button.OnClick(EventArgs e)处
  在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)处
  在System.Windows.Forms.Control.WmMouseUp(消息和m,MouseButtons按钮,Int32单击)处
  在System.Windows.Forms.Control.WndProc(Message& m)
  在System.Windows.Forms.ButtonBase.WndProc(Message& m)处
  在System.Windows.Forms.Button.WndProc(Message& m)
  在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)处
  在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)处
  在System.Windows.Forms.NativeWindow.Callback处(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

值得一看...这是我的跟踪配置文件

    < system.diagnostics>
      < switches>
       < add name ="TimerSwitch";值="4" />
       < add name ="DisplaySwitch";值="4" />
       < add name ="BusinessSwitch"值="4" />
       < add name ="DataAccessSwitch";值="4" />
     </switches>
      < trace autoflush ="true"; indentsize ="4">
       <侦听器>
         < add name =" FileListener" type ="System.Diagnostics.TextWriterTraceListener" initializeData ="traceLog.txt"; />
       </listeners>
      </trace>
    </system.diagnostics>

解决方案

感谢您的信息!我建议将您的问题发布到MS论坛之一中,

<跨度样式="color:#0066dd"> Windows开发人员中心
> Windows窗体论坛 > Windows窗体数据控件和数据绑定

位于此处: 祝您度过愉快的一天!


Okay, I get the exception in my winforms application.  This application runs fine in VS2010, it also writes trace info to a file that I've configured in my configuration file.

When I deploy the program via the Setup installer (I build a setup project in VS2010), it installs nicely.  The application runs fine as long as you don't do any DB UPDATES - if you do, the above error is generated.  Another clue, all my tracing is not writing to the file as per my configuration file.  I've done the normal things of checking that the files and folders are not set to READ-ONLY.

I'm installing the program on a Windows7 machine.   I suspect that the application does not have permission to write files or update the database - I have no idea how one sets that up for a winform application - is it via the app.manifest????  I'm clueless on this... and I've wasted hours trying to figure out why this is happening.   I can't figure out why my tracelog.txt file is not even generating (I've set the TRACE constant on in the configuration manager)... my application generates a lot of output when I run it thru VS2010 but not a single line when deployed and installed.  Is this some sort of permissions issue and how the world could I determine that?  Thanks in advance to anyone who can help.


Here is the Message:

System.Data.SqlClient.SqlException: Failed to update database "C:\PROGRAM FILES\PLAY\PDMS\DATABASE\MEDIASLIDES.MDF" because the database is read-only.
   at PDMS.clsApplicationFactory.Update(clsApplication app)
   at PDMS.formApplicationSettings.buttonSave_Click(Object sender, EventArgs e)
   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)

For what it's worth... here is my configuration file for the trace

    <system.diagnostics>
      <switches>
        <add name="TimerSwitch" value="4" />
        <add name="DisplaySwitch" value="4" />
        <add name="BusinessSwitch" value="4" />
        <add name="DataAccessSwitch" value="4" />
      </switches>
      <trace autoflush="true" indentsize="4">
        <listeners>
          <add name="FileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="traceLog.txt" />
        </listeners>
      </trace>
    </system.diagnostics>

Hi,

 

Thank you for your post!  I would suggest posting your question in one of the MS Forum,

Windows Developer Center > Windows Forms Forums > Windows Forms Data Controls and Databinding

located here: http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/threads

Have a great day!


这篇关于WinForms无法更新数据库,因为该数据库是只读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆