locked
creating a dbf file in asp.net RRS feed

  • Question

  • User351619809 posted

    Hello everyone,

    I am trying to create a dbf file in C#. Somehow when I am trying to open the connection to OLEDB, the program terminates without throwing an exception. Below is the code:

    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;
    
                }
            
            }

     The program terminates at this point:

    dBaseConnection.Open();


    I checked the event logs and that does not help either. Below is the error log from event log:

    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

    any help will be greatly appreciated.

     

    Monday, June 26, 2017 6:56 PM

Answers

  • User-707554951 posted

    Hi anjaliagarwal5@yahoo.com

    It seem that you connection string is not correct.

    Check your connection string carefully.

    I use SqlClient, it works well.

                string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                using (SqlConnection connection = new SqlConnection(constr))
                {
                    string insertSQL = "CREATE TABLE [dbo].[CreatesTable]( [Id] INT NOT NULL PRIMARY KEY, [Name] NCHAR(10) NULL)";
                    SqlCommand command = new SqlCommand(insertSQL);
                    // Set the Connection to the new OleDbConnection.
                    command.Connection = connection;
                    // Open the connection and execute the insert command.
                    connection.Open();
                    command.ExecuteNonQuery();
                    // The connection is automatically closed when the
                    // code exits the using block.
                }

    Best regard

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 27, 2017 8:57 AM

All replies

  • User-707554951 posted

    Hi anjaliagarwal5@yahoo.com

    It seem that you connection string is not correct.

    Check your connection string carefully.

    I use SqlClient, it works well.

                string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                using (SqlConnection connection = new SqlConnection(constr))
                {
                    string insertSQL = "CREATE TABLE [dbo].[CreatesTable]( [Id] INT NOT NULL PRIMARY KEY, [Name] NCHAR(10) NULL)";
                    SqlCommand command = new SqlCommand(insertSQL);
                    // Set the Connection to the new OleDbConnection.
                    command.Connection = connection;
                    // Open the connection and execute the insert command.
                    connection.Open();
                    command.ExecuteNonQuery();
                    // The connection is automatically closed when the
                    // code exits the using block.
                }

    Best regard

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 27, 2017 8:57 AM
  • User753101303 posted

    Hi,

    You have the same message even if you get rid of the catch block that does nothing else than assigning the error message to a variable which is not used ?

    Tuesday, June 27, 2017 9:00 AM