I am testing some things out in an Access DB (This will be going away, but until I document all functionality, its what I've got) and when I debug my code, I am getting 0 data back from my query. The connection opens just fine, just no data. Anything about the below code stick out to you guys?
Connection String
<connectionStrings>
<add name="DefaultConnection" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Projects\\Facts\LoginNew2000.mdb; Persist Security Info=False;" providerName="System.Data.SqlClient" />
</connectionStrings>
Query, returning no data
OleDbConnection myAccessConn = null;
try
{
myAccessConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
myAccessConn.Open();
OleDbCommand myAccessCommand = new OleDbCommand("select User_Name from Managers");
myAccessCommand.Connection = myAccessConn;
myAccessCommand.Prepare();
var rdr = myAccessCommand.ExecuteReader();
while (rdr.Read())
{
var x = rdr[0].ToString();
}
}
catch (Exception ex)
{
Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
}
finally
{
myAccessConn.Close();
}
return View();
The above code, while debugging, skips directly from the start of the while loop to the ending try block curly brace.