Hum, have you tested the connection?
I suggest you consider letting visual studio "build" the connection for you.
If this is a webforms project, then you can try:
project->"my project name" properties (usually the last choice).
And then use "settings".
If you click on the [...], then the connection builder is launched.
We are assuming that you have say SQL server express up and running.
But, using the connection builder can help, and it does have a "test" conneciton.
So, after clicking on [...], then we get this:
So, above is nice, since then it will "create/put" the connection you create into web config for you.
and with the test connection button then you can test/try the database connection without having to run code just yet.
so, for example, in above I created a few connections.
And, in code, I can thus now say do this:
void LoadGrid()
{
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
{
string strSQL =
@"SELECT * FROM tblHotelsA ORDER BY HotelName";
using (SqlCommand cmdSQL = new SqlCommand(strSQL, conn))
{
conn.Open();
DataTable rstData = new DataTable();
rstData.Load(cmdSQL.ExecuteReader());
GridView1.DataSource = rstData;
GridView1.DataBind();
}
}
}
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta, Canada