我需要将.mdb数据库附加到C#桌面应用程序

时间:2016-08-24 11:27:33

标签: c# .net windows forms jit

我将数据库包含到项目文件中并构建解决方案,当我在另一台机器上运行应用程序时出现错误

**************例外文字**************

  

System.Configuration.ConfigurationErrorsException:配置   系统无法初始化--->   System.Configuration.ConfigurationErrorsException:无法识别   配置部分配置。 (C:\ Documents and   设置\ WINDOWS \桌面\ IstanbulFood \ POSApp \ IstanbulFoodPOS \ BIN \调试\ IstanbulFoodPOS.exe.Config   第8行)   System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(布尔   ignoreLocal)at   System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors   schemaErrors)at   System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()at   System.Configuration.ClientConfigurationSystem.EnsureInit(字符串   configKey)---内部异常堆栈跟踪结束--- at   System.Configuration.ClientConfigurationSystem.EnsureInit(字符串   configKey)   System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(字符串   sectionName)at   System.Configuration.ConfigurationManager.GetSection(字符串   sectionName)at   System.Configuration.ConfigurationManager.get_ConnectionStrings()at   IstanbulFoodPOS.dataAccess..ctor()in   D:\ IstanbulFood \ POSApp \ IstanbulFoodPOS \ dataAccess.cs:第17行at   IstanbulFoodPOS.Login.EnterButton_Click(Object sender,EventArgs e)in   D:\ IstanbulFood \ POSApp \ IstanbulFoodPOS \ Login.cs:第37行   System.Windows.Forms.Control.OnClick(EventArgs e)at   System.Windows.Forms.Button.OnClick(EventArgs e)at   System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)at at   System.Windows.Forms.Control.WmMouseUp(Message& m,MouseButtons   System.Windows.Forms.Control.WndProc上的按钮,Int32单击)(消息&   m)在System.Windows.Forms.ButtonBase.WndProc(Message& m)at at   System.Windows.Forms.Button.WndProc(Message& m)at   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)

**************已加载的程序集**************

mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
IstanbulFoodPOS
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Documents%20and%20Settings/windows/Desktop/IstanbulFood/POSApp/IstanbulFoodPOS/bin/Debug/IstanbulFoodPOS.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.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.

配置文件:

<?xml version="1.0"?>
<configuration>
    <configSections> </configSections>
    <connectionStrings>
        <add name="IstanbulFoodDBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\IstanbulFood\POSApp\IstanbulFoodPOS\IstanbulFoodDB‌​.mdbb;Persist Security Info=True" providerName="System.Data.OleDb"/>
    </connectionStrings>
    <configuration>
        <system.windows.forms jitDebugging="true"/>
    </configuration>
    <startup>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

4 个答案:

答案 0 :(得分:1)

你确定在另一台机器上的文件路径“D:\ IstanbulFood \ POSApp \ IstanbulFoodPOS \ IstanbulFoodDB .mdbb”是一样的吗?

答案 1 :(得分:0)

看起来您遇到连接字符串问题。您可以在here中找到示例。

示例连接字符串应为;

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb; Persist Security Info=False;

答案 2 :(得分:0)

该异常是由于app.config文件中的其他配置元素造成的。尝试将<system.windows.forms jitDebugging="true"/>元素向上移动一层嵌套,例如:

<?xml version="1.0"?>
<configuration>
    <configSections> </configSections>
    <connectionStrings>
        <add name="IstanbulFoodDBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\IstanbulFood\POSApp\IstanbulFoodPOS\IstanbulFoodDB‌​.mdbb;Persist Security Info=True" providerName="System.Data.OleDb"/>
    </connectionStrings>

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

    <startup>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

答案 3 :(得分:0)

我已将数据源更改为:

Data Source =|DataDirectory|\IstanbulFoodDB.mdb;

当我在另一台机器上运行应用程序时,它正在工作; 这也是Config文件:

<?xml version="1.0"?>
<configuration>
  <configSections> </configSections>
  <connectionStrings>
    <add name="IstanbulFoodDBConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\IstanbulFoodDB.mdb;Persist Security Info=False;" providerName="System.Data.OleDb"/>
  </connectionStrings>

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

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>