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

Complete 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
In Myini.dbupgrade1 () position Program.cs: line number 348
In Program.main () position Program.cs: line number 738}

cause of error:
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=""这里是你的ACCESS数据库文件的路径"+  ";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; ".

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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

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.