C
ChrisC
I am a relative newbie to .NET - two weeks, using everyday. My problem
is this. I have my asp.net application where the web.config contains
the database connection string. Normally i access this fine with
Application[ "connectionString" ].
However, I am now trying to use a unit testing framework (csunit
1.9.2) and when I try and run the tests I have created it is saying
"The ConnectionString property has not been initialized". The piece
of code it is using runs fine if I access it by clicking a button
that triggers it in one of my aspx pages, but not when it is
initiated by the unit test class.
Potential troubles - the class I am running the method in is a
standalone utility class ie it doesnt have a aspx page associated.
Dont know if this matters or not....
public string getXmlCommandByName( string commandName )
{
SqlConnection conn;
using (conn = new SqlConnection(
ConfigurationSettings.AppSettings[ "connectionString"
] ) )
{
conn.Open();
string sqlString = "SELECT xml FROM PDSXML WHERE command =
" + commandName;
SqlCommand request = new SqlCommand( sqlString, conn );
SqlDataReader results =
request.ExecuteReader();
return results.GetValue( 0 ).ToString();
}
}
As you can see i have been trying using different ways of accessing
the web.config
Help!
is this. I have my asp.net application where the web.config contains
the database connection string. Normally i access this fine with
Application[ "connectionString" ].
However, I am now trying to use a unit testing framework (csunit
1.9.2) and when I try and run the tests I have created it is saying
"The ConnectionString property has not been initialized". The piece
of code it is using runs fine if I access it by clicking a button
that triggers it in one of my aspx pages, but not when it is
initiated by the unit test class.
Potential troubles - the class I am running the method in is a
standalone utility class ie it doesnt have a aspx page associated.
Dont know if this matters or not....
public string getXmlCommandByName( string commandName )
{
SqlConnection conn;
using (conn = new SqlConnection(
ConfigurationSettings.AppSettings[ "connectionString"
] ) )
{
conn.Open();
string sqlString = "SELECT xml FROM PDSXML WHERE command =
" + commandName;
SqlCommand request = new SqlCommand( sqlString, conn );
SqlDataReader results =
request.ExecuteReader();
return results.GetValue( 0 ).ToString();
}
}
As you can see i have been trying using different ways of accessing
the web.config
Help!