The ConnectionString property has not been initialized!!!!!!!!!!!!!!

Discussion in 'ASP.NET / ASP.NET Core' started by DivebombInc, Feb 6, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Now on to the next prob...
    I can't connect to SQL for some reason now. Everything is set up the same.
    Here is my code:
    header.ascx.vb
    Dim connStr As SqlConnection
    Dim cmdCartCount As SqlCommand
    Dim paramCartCount As SqlParameter
    Dim intCartCount As Integer
    If Request.QueryString("OrderID") Is Nothing Then
    connStr = New SqlConnection(ConfigurationSettings.AppSettings("sqlCon.ConnectionString"))
    cmdCartCount = New SqlCommand("GetCartCount", connStr)
    cmdCartCount.CommandType = CommandType.StoredProcedure
    cmdCartCount.Parameters.Add("@orderID", "001")
    connStr.Open()
    web.config

    <configuration>
    <appSettings>
    <add key="sqlCon.ConnectionString" value="Data Source=#####;Initial Catalog=#####;User Id=#####;Password=#####" />
    </appSettings>
    <system.web>
    Any idea why this won't start talking?
     
  2. ...Give the conn string a try like this:

    <connectionStrings>
    <clear />
    <remove name="sqlCon.ConnectionString"/>
    <add name="sqlCon.ConnectionString" connectionString="Data Source=tcp:servername;Initial Catalog=database;User ID=user;Password=password;" providerName="System.Data.SqlClient" />
    </connectionStrings>
     
  3. Thanks. This conn string is working I think
    <add key="sqlCon.ConnectionString" value="Data Source=#####;Initial Catalog=#####;User ID=#####;Password=#####;" />
    Now on to the next issue
    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:





    Code:
    Line 48:             cmdCartCount.CommandType = CommandType.StoredProcedure
    Line 49:             cmdCartCount.Parameters.Add("@orderID", "001")
    Line 50:             connStr.Open()
    Line 51:             cmdCartCount.ExecuteNonQuery()
    Line 52:             Me.lblItemsInCart.Visible = False

    Here's the code that I've used before successfully
    Dim connStr As SqlConnection
    Dim cmdCartCount As SqlCommand
    Dim paramCartCount As SqlParameter
    Dim intCartCount As Integer
    If Request.QueryString("OrderID") Is Nothing Then
    connStr = New SqlConnection(ConfigurationSettings.AppSettings("sqlCon.ConnectionString"))
    cmdCartCount = New SqlCommand("GetCartCount", connStr)
    cmdCartCount.CommandType = CommandType.StoredProcedure
    cmdCartCount.Parameters.Add("@orderID", "001")
    connStr.Open()
    cmdCartCount.ExecuteNonQuery()
     
  4. I just figured it out. I had the following in my code page
    Imports System.Web.Security
    Imports System.Data.SqlClient
    Imports System.Text
    and forgotthe following
    Imports System.Data
    Thanks for your help with this issue. I'm sure I'll be back soon with something else.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page