The System.InvalidOperationException:ConnectionString property has not been initialized.

Source: Internet
Author: User

C # using OLE DB to manipulate access
Provider=Microsoft.Jet.OLEDB.4.0;Data source= "+ NewFileName +"; User Id=uid; Jet oledb:database password=pwd; ";

full error message:
{The System.InvalidOperationException:ConnectionString property has not been initialized.}
In System.Data.OleDb.OleDbConnection.PermissionDemand ()
In System.Data.OleDb.OleDbConnectionFactory.PermissionDemand (DbConnection outerconnection)
In System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection outerconnection, dbconnectionfactory ConnectionFactory)
In System.Data.OleDb.OleDbConnection.Open ()
In System.Data.Common.DbDataAdapter.FillInternal (DataSet DataSet, datatable[] DataTables, Int32 Startrecord, Int32 MaxRecords, String srctable, IDbCommand command, CommandBehavior behavior)
In System.Data.Common.DbDataAdapter.Fill (DataSet DataSet, Int32 Startrecord, Int32 maxrecords, String srctable, IDbCommand command, CommandBehavior behavior)
In System.Data.Common.DbDataAdapter.Fill (DataSet DataSet, String srctable)
In Public.DB.GetDataTable (String Sql) position Public\db.cs: line number 44
At Myini.dbupgrade1 () position Program.cs: line number 348
At Program.main () position Program.cs: line number 738}

Error Reason:
The ConnectionString property has not been initialized. Only the Connection object is created, and the ConnectionString property of the Connection object is not set;

Workaround:
Set the ConnectionString property of the connection object, such as the following code:

Connection.connectionstring  = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + "here is the path to your Access database file" +  "; User Id=uid; Jet oledb:database password=pwd; ";

If the database does not have a password, you do not need to add the following "User Id=uid;" Jet oledb:database password=pwd; ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.