C# MDB database connection string trouble

Jelmer

Well-known member
Joined
Jan 11, 2006
Messages
96
Hello

Im building an application with a connection to a MDB database (access).
Ive build the code like this:

Code:
            IniFile ini = new IniFile("test.ini");
            database = ini.IniReadValue("Info", "Database");
            connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + database + ";User Id=admin;Password=;";
            SqlConnection cn = new SqlConnection(connectionString);
            string sCommand = "select * from Klanten";

But ill get an error.. .Net said that the string is not correct.
On an other part of the program i use this code:

Code:
database = ini.IniReadValue("Info","Database");
	
connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"; 
connectionString += @"Data Source=" + database + ";"; 

Connection.ConnectionString = connectionString;
Connection.Open();

That last part works !!

But why the first not ?
Wats wrong.. database contains the full path to the database like: c:\database.mdb
 
In the first example you are useing an UserId.
Are you sure the db needs it?

If the second ConString is working remove the user/pwd from the firstone.
 
FZelle said:
In the first example you are useing an UserId.
Are you sure the db needs it?

If the second ConString is working remove the user/pwd from the firstone.

Doesnt mather.. ill get this error:

Keyword not supported :provider

On this line:

SqlConnection cn = new SqlConnection(connectionString);
 
Back
Top