Answered by:
acces connection strings

Question
-
User-86436190 posted
Hello i want to connect with my acces database.
In my web.config file i use this code:
<connectionStrings>
<add name="RandapparatuurConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|randapparatuur.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
this is the code from my aspx file
// Ophalen van de connectiestring
string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString"].ToString();
conn = new SqlConnection(connString);
// Aanmaken commando
string sql =
"SELECT * FROM tblLector";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
// databinden!!
gv.DataSource = reader;
gv.DataBind();
//sluiten connectie
conn.Close();
}
catch(Exception ex)
{
lblFout.Text = ex.Message;
}but i get the folowwing error code: Keyword not supported: 'provider'.
when i try i with aan sql database it works.
cany somebody helps me please.
thx
Tuesday, April 13, 2010 10:17 AM
Answers
-
User-60558687 posted
To connect to your access database Use OleDbConnection class not SqlConnection. SqlConnection is for Sql server database.
Similarly use OleDbCommand command instead of SqlCommand.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 13, 2010 11:19 AM -
User-1199946673 posted
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 13, 2010 11:28 AM -
User-1460196090 posted
Hi again.
You should have:
// Ophalen van de connectiestring string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString"].ToString(); conn = new OleDbConnection(connString); // Aanmaken commando string sql = "SELECT * FROM tblLector"; OleDbCommand cmd = new OleDbCommand(sql, conn); conn.Open(); OleDbDataReader reader = cmd.ExecuteReader(); // databinden!! gv.DataSource = reader; gv.DataBind(); //sluiten connectie conn.Close(); } catch (Exception ex) { lblFout.Text = ex.Message; }
and don't forget to add:
using System.Data.OleDb; //instead of using System.Data.SqlClient using System.Configuration;
Hope this helps,
Hajan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 14, 2010 3:06 PM -
User1845091919 posted
Take a look at this site, you'll find plenty of settings for all sorts of databases:
http://www.connectionstrings.com/
You should find your settings there, Wolfgang
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 14, 2010 5:25 PM
All replies
-
User-60558687 posted
To connect to your access database Use OleDbConnection class not SqlConnection. SqlConnection is for Sql server database.
Similarly use OleDbCommand command instead of SqlCommand.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 13, 2010 11:19 AM -
User-1199946673 posted
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 13, 2010 11:28 AM -
User-1460196090 posted
Hi again.
You should have:
// Ophalen van de connectiestring string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString"].ToString(); conn = new OleDbConnection(connString); // Aanmaken commando string sql = "SELECT * FROM tblLector"; OleDbCommand cmd = new OleDbCommand(sql, conn); conn.Open(); OleDbDataReader reader = cmd.ExecuteReader(); // databinden!! gv.DataSource = reader; gv.DataBind(); //sluiten connectie conn.Close(); } catch (Exception ex) { lblFout.Text = ex.Message; }
and don't forget to add:
using System.Data.OleDb; //instead of using System.Data.SqlClient using System.Configuration;
Hope this helps,
Hajan
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 14, 2010 3:06 PM -
User1845091919 posted
Take a look at this site, you'll find plenty of settings for all sorts of databases:
http://www.connectionstrings.com/
You should find your settings there, Wolfgang
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, April 14, 2010 5:25 PM -
User-86436190 posted
thx
this problem is solved
Thursday, April 15, 2010 5:52 AM