The connection always times out without generating an error message even though it is within trycatch. I suspect there is something wrong with the connection string. This is what I currently have:
string path = @"C:\PATH\TO\wantedDB.mdb";
if (!File.Exists(path))
throw new FileNotFoundException("File not found.");
else
Console.WriteLine("File found."); // File is found, so nothing wrong with that.
string connectionstring = "Database=wantedDB;AttachDBFilename=" +
path + ";Server=(local)";
using (SqlConnection conn = new SqlConnection(connectionstring))
{
Console.WriteLine("Opening connection...");
conn.Open();
Console.WriteLine("Connection opened."); // Program never gets here.
I have also tried a relational path in connection string like:
string connectionstring = "Database=wantedDB;AttachDBFilename=\"wantedDB.mdb\";Server=(local)";
The db is not protected by a password. I have MS Access installed, does that affect this somehow? What am I missing?
To connect to a mdb file you should use the OLEDB connector: