SQLConnection.Open(); throwing exception
Posted
by flavour404
on Stack Overflow
See other posts from Stack Overflow
or by flavour404
Published on 2010-03-08T00:26:29Z
Indexed on
2010/03/08
0:30 UTC
Read the original article
Hit count: 430
Hi,
Updating an old piece of software but in order to maintain backward compatibility I need to connect to a .mdb (access) database.
I am using the following connection but keep getting an exception, why?
I have validated the path, database existence etc. and that is all correct.
string Server = "localhost";
string Database = drive + "\\btc2\\state\\states.mdb";
string Username = "";
string Password = "Lhotse";
string ConnectionString = "Data Source = " + Server + ";" +
"Initial Catalog = " + Database + ";" +
"User Id = '';" +
"Password = " + Password + ";";
SqlConnection SQLConnection = new SqlConnection();
try
{
SQLConnection.ConnectionString = ConnectionString;
SQLConnection.Open();
}
catch (Exception Ex)
{
// Try to close the connection
if (SQLConnection != null)
SQLConnection.Dispose();
//
//can't connect
//
// Stop here
return false;
}
© Stack Overflow or respective owner