I'm working on a program that gets data from a database on an .mdf file and populates a listbox with the results. I'm getting an error that says "An OLE DB Provider was not specified in the ConnectionString."
I can't seem to figure out what is the correct string to use for a provider. In my particular case, what am I supposed to do to get it to read the .mdf correctly?
sConnection = "Data Source=.\\SQLEXPRESS; AttachDbFilename = StudentData.mdf;";
dbConn = new OleDbConnection(sConnection);
dbConn.Open();
sql = "SELECT * FROM StudentData;";
dbCmd = new OleDbCommand();
dbCmd.CommandText = sql;
dbCmd.Connection = dbConn;
dbReader = dbCmd.ExecuteReader();
while (dbReader.Read())
{
aMember = new
Member(dbReader["FirstName"].ToString(),
dbReader["LastName"].ToString());
this.OutputListBox.Items.Add(aMember);
}
dbReader.Close();
dbConn.Close();
Update: I've changed the connection string to:
sConnection = "Provider = SQLNCLI11;" +
"Data Source = (LocalDB)/MSSQLLocalDB;" +
"AttachDbFilename = \"c:/users/tevin/documents/visual studio 2015/Projects/DbReader/DbReader/StudentData.mdf\";" +
"Connect Timeout = 30;";
However now I am getting the errors "Invalid authorization specification" and "Invalid connection string attribute".