Thursday, February 9, 2012

ASP.NET + SQL 2005

Guys, I have a problem with setting up connection from asp file to MS Sql db.
I'm using Web.Config as the file to setup the connection:
<connectionStrings
<add name="AMConn" connectionString="Data Source=TWS_WS04;Initial Catalog=AccessMed;Integrated Security=True"

providerName="System.Data.SqlClient" /
</connectionStrings
My connection to the db from aspx file:

string strSQL = "SELECT * FROM Client";

SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["AMConn"]);

SqlDataAdapter myCommand = new SqlDataAdapter(strSQL, myConnection);

DataSet objDataSet = new DataSet();

myCommand.Fill(objDataSet, "Client");

DataTable objDataTable = objDataSet.Tables["Client"];

And the error message: "The ConnectionString property has not been initialized."

I know that there is a problem with my connection because no matter what I put as AppSettings["ANYTHING I WANT"]); - the error is always the same.

I'm new to asp.net and I would appreciate any help.

Thanks,

JimUse the specific newsgroups for 2005 questions:
http://communities.microsoft.com/ne...welcomePage.htm

--
David Portas
SQL Server MVP
--|||aspx.cs file. I'm using C# as code behind.

"draku" <jkafara@.hotmail.com> wrote in message

My connection to the db from aspx file:|||GOT IT!
If anyone ever have the same problem this is the solution:
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrin gs["AMConn"].ConnectionString);

"draku" <jkafara@.hotmail.com> wrote in message news:dhhakm$dln$1@.inews.gazeta.pl...
Guys, I have a problem with setting up connection from asp file to MS Sql db.
I'm using Web.Config as the file to setup the connection:
<connectionStrings
<add name="AMConn" connectionString="Data Source=TWS_WS04;Initial Catalog=AccessMed;Integrated Security=True"

providerName="System.Data.SqlClient" /
</connectionStrings
My connection to the db from aspx file:

string strSQL = "SELECT * FROM Client";

SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["AMConn"]);

SqlDataAdapter myCommand = new SqlDataAdapter(strSQL, myConnection);

DataSet objDataSet = new DataSet();

myCommand.Fill(objDataSet, "Client");

DataTable objDataTable = objDataSet.Tables["Client"];

And the error message: "The ConnectionString property has not been initialized."

I know that there is a problem with my connection because no matter what I put as AppSettings["ANYTHING I WANT"]); - the error is always the same.

I'm new to asp.net and I would appreciate any help.

Thanks,

Jim

No comments:

Post a Comment