打开与 OLEDB 的连接终止代码

Opening the connection to OLEDB terminates the code

我正在尝试用 C# 创建一个 dbf 文件。不知何故,当我试图打开与 OLEDB 的连接时,程序终止而没有抛出异常。下面是代码:

private void CreateDBFFile()
    {
        try
        {
            using (var dBaseConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; " + @" Data Source=k:\Temp; " + @"Extended Properties=dBase IV"))
            {
                dBaseConnection.Open();

                string createTableSyntax =
                    "Create Table Person " +
                    "(Name char(50), City char(50), Phone char(20), Zip decimal(5))";
                var cmd = new OleDbCommand(createTableSyntax, dBaseConnection);
                cmd.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            string x = ex.Message;

        }

    }

这里抛出错误:

dBaseConnection.Open();

我检查了事件日志,但也无济于事。以下是事件日志中的错误日志:'

Faulting application name: iisexpress.exe, version: 10.0.14358.1000, time 
stamp: 0x574fc56b
Faulting module name: clr.dll, version: 4.6.1649.1, time stamp: 0x58f97fe6
 Exception code: 0xc0000005
Fault offset: 0x0045068d
 Faulting process id: 0x3354
 Faulting application start time: 0x01d2eeacd40d1e91
Faulting application path: C:\Program Files (x86)\IIS Express\iisexpress.exe
 Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
 Report Id: 18960866-5aa0-11e7-b3f6-005056c00008

任何帮助将不胜感激。

您建立联系的方式并不理想。

改为执行此操作,然后单步执行代码,您应该能够得到异常,否则它会起作用: 将您的连接字符串放入 web.config.

  <connectionStrings>
    <add name="Connection" connectionString="Data Source=k:\Temp; xtended Properties=dBase IV Provider=Microsoft.Jet.OLEDB.4.0" />    
  </connectionStrings>


string connection = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
           using (OleDbConnection dBaseConnection = new OleDbConnection(connection))
           {
               if (dBaseConnection.State == ConnectionState.Closed)
               {
                   dBaseConnection.Open();
               }
           }

一旦我从我的连接字符串中删除了这一行

     "Extended Properties=dBase IV ". 

代码开始运行。