Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2004, 05:03 PM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old July 12th, 2004, 11:20 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please modify the code as:

<%@ Import NameSpace="System.Configuration" %>

Dim oConn As New SqlConnection _
(ConfigurationSettings.AppSettings("connstring"))
oConn.Open()
.....
.....
Dim MyCommand As SQLCommand
MyCommand= New SqlCommand("mSP_YYYY", oConn)
.....
.....


Om Prakash
 
Old July 13th, 2004, 12:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Your connection string needs to specify an initial catalog (instead of database) and the integrated security option.

Brian
 
Old January 5th, 2007, 06:25 AM
Registered User
 
Join Date: Jan 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Plz modify ur web config file code as

 <appSettings>
    <add key="myconnectionstring"
         value="server=compname; database=mydb; integrated security=SSPI" />
  </appSettings>


and the asp file as follows..
onPage_Load Event

Dim strConnection As String = ConfigurationSettings.AppSettings("myconnectionstr ing")
  Dim objConnection As New SqlConnection(strConnection)

I think this can work for U.
:D






Similar Threads
Thread Thread Starter Forum Replies Last Post
web.config dpkbahuguna ASP.NET 3.5 Basics 2 August 26th, 2008 09:41 AM
web.config vs. app.config darlo Visual Studio 2005 11 August 20th, 2008 07:23 AM
Web Config SteveP55419 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 January 3rd, 2007 04:19 PM
web.config nagsumam .NET Framework 1.x 3 November 29th, 2006 10:09 AM
Defining Application Root in web.config wdwright ASP.NET 2.0 Basics 0 August 22nd, 2006 04:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.