defining connstring in web.config
Hi,
could somebody tell me what am I missing here please?
I have defined my connstring in web.config file as follow:
________________________________________________
<appSettings>
<add key="connstring" value="server=serversqlnine;database=XXXXX;uid=XXX XY;password=XXXXZ;" />
</appSettings>
_________________________________________________
and in the asp.net page:
__________________________________________________ _
<%@ Import NameSpace="System.Configuration" %>
Dim oConn As New SqlConnection _
(ConfigurationSettings.AppSettings("connstring"))
Dim MyCommand As SQLCommand
MyCommand= New SqlCommand("mSP_YYYY", oConn)
.....
oConn.Open()
.....
__________________________________________________ __
I get this error message:
The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.
Source Error:
Line 48: MyParam.Direction = ParameterDirection.Output
Line 49:
Line 50: oConn.Open()
Line 51: MyCommand.ExecuteNonQuery()
Source File: c:\inetpub\wwwroot\XX_files\mm.aspx Line: 50
Stack Trace:
[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.SqlClient.SqlConnection.Open() +433
ASP.mm_aspx.CustomValidator_Check(Object s, ServerValidateEventArgs e) in c:\inetpub\wwwroot\XX_files\mm.aspx:50
System.Web.UI.WebControls.CustomValidator.OnServer Validate(String value) +136
System.Web.UI.WebControls.CustomValidator.Evaluate IsValid() +88
System.Web.UI.WebControls.BaseValidator.Validate() +138
System.Web.UI.Page.Validate() +234
System.Web.UI.HtmlControls.HtmlInputButton.System. Web.UI.IPostBackEventHandler.RaisePostBackEvent(St ring eventArgument) +33
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
______________________________________
Thanks
|