Jelmer Posted February 5, 2006 Posted February 5, 2006 Hello I'm building an application with a connection to a MDB database (access). I've build the code like this: 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 i'll get an error.. .Net said that the string is not correct. On an other part of the program i use this 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 Quote
FZelle Posted February 5, 2006 Posted February 5, 2006 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. Quote
Jelmer Posted February 5, 2006 Author Posted February 5, 2006 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.. i'll get this error: Keyword not supported :'provider' On this line: SqlConnection cn = new SqlConnection(connectionString); Quote
Administrators PlausiblyDamp Posted February 6, 2006 Administrators Posted February 6, 2006 Use the OleDB classes if you are using Acess, SqlClient only works with SqlServer Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Nerseus Posted February 6, 2006 *Experts* Posted February 6, 2006 Best website idea, EVER, for a DB programmer: http://www.connectionstrings.com/ -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Jelmer Posted February 6, 2006 Author Posted February 6, 2006 tried that.. used that connetion string.. but same error.. Now i found this example.. i build it into my program and think that it will work.. but had no time to do that .. http://www.codeproject.com/cs/database/csharpaccessdb.asp Quote
robertsams23 Posted July 1, 2009 Posted July 1, 2009 try connetionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=yourdatabasename.mdb;" http://csharp.net-informations.com/ado.net/csharp-connection-string.htm rob. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.