C# access conection error

Discussion in 'Databases' started by villagecirc, Nov 17, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. My code is error free but when I go to veiw it in the browser I get the following error does anyone reconize this error message[V]

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [InvalidOperationException: The ConnectionString property has not been initialized.]
    System.Data.OleDb.OleDbConnection.Open() +203
    Test.Test.ReturnDataset(String cmdText) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.net\test\test.aspx.cs:39
    Test.Test.Page_Load(Object sender, EventArgs e) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.net\test\test.aspx.cs:28
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +731


    I am at a loss and just when I thought I had it going I seem even further than I started if anyone has any idea what I have done wrong or any other suggestions in the matter it would be greatly apreciated....[V]


    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  2. conection string within web.config within same aplication is....

    <configuration>
    <appSettings>
    <!-- add this kind of key -->
    <add key="myConn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\web\villagecirc\htdocs\_database\bt.mdb"/>
    </appSettings>
    <system.web>




    code in its entirety....


    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Configuration;
    using System.Web.Configuration;

    namespace Test
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class Test : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button1;

    private void Page_Load(object sender, System.EventArgs e)
    {

    // Put user code to initialize the page here
    DataSet MYDS = ReturnDataset("SELECT * FROM Events");



    }

    public static DataSet ReturnDataset(string cmdText)
    {
    OleDbConnection conn = new OleDbConnection ();
    {
    conn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
    conn.Open();

    OleDbDataAdapter da = new OleDbDataAdapter ();
    OleDbCommand commSQL;
    commSQL = new OleDbCommand();
    commSQL.Connection = conn;
    commSQL.CommandType= CommandType.StoredProcedure;
    commSQL.CommandText=cmdText;
    da.SelectCommand = commSQL ;

    DataSet ds = new DataSet();
    da.Fill (ds) ;

    conn.Close() ;
    return ds;
    }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
    }
    }


    Please note the code is error free in the debugger but gives the previous posted generic error message when opened in a browser

    I used ftp to place the database within the database folder listed within the web.config file [?]

    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    Please post your code.
    This error is too general for people to help

    quote:Originally posted by villagecirc

    My code is error free but when I go to veiw it in the browser I get the following error does anyone reconize this error message[V]

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [InvalidOperationException: The ConnectionString property has not been initialized.]
    System.Data.OleDb.OleDbConnection.Open() +203
    Test.Test.ReturnDataset(String cmdText) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.net\test\test.aspx.cs:39
    Test.Test.Page_Load(Object sender, EventArgs e) in c:\documents and settings\smpaulson\vswebcache\www.villagecircle.net\test\test.aspx.cs:28
    System.Web.UI.Control.OnLoad(EventArgs e) +67
    System.Web.UI.Control.LoadRecursive() +35
    System.Web.UI.Page.ProcessRequestMain() +731


    I am at a loss and just when I thought I had it going I seem even further than I started if anyone has any idea what I have done wrong or any other suggestions in the matter it would be greatly apreciated....[V]


    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
    </blockquote id="quote"></font id="quote">
     
  4. Your key name is myConn, not ConnectionString
     
  5. Bruce

    Bruce DiscountASP.NET Staff

    I think the path should look like

    E:\web\villagecirc\htdocs\database\T.mdb

    instead of

    E:/web/villagecirc/htdocs/_database/BT.mdb



    quote:Originally posted by villagecirc

    thank you that was it now I am getting a more specific error


    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 5, position 85.

    Source Error:


    Line 3: <appSettings>
    Line 4: <!-- add this kind of key -->
    Line 5: <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:/web/villagecirc/htdocs/_database/BT.mdb" />
    Line 6: </appSettings>
    Line 7: <system.web>


    Source File: E:\web\villagecirc\htdocs\Test\web.config Line: 5


    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.903

    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
    </blockquote id="quote"></font id="quote">
     
  6. thank you that was it now I am getting a more specific error


    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 5, position 85.

    Source Error:


    Line 3: <appSettings>
    Line 4: <!-- add this kind of key -->
    Line 5: <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:/web/villagecirc/htdocs/_database/BT.mdb" />
    Line 6: </appSettings>
    Line 7: <system.web>


    Source File: E:\web\villagecirc\htdocs\Test\web.config Line: 5


    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.903

    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  7. for some odd reason I am getting an error on the closing tag


    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 6, position 5.

    Source Error:


    Line 4: <!-- add this kind of key -->
    Line 5: <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='e:\web\villagecirc\htdocs\_database\BT.mdb'/>
    Line 6: </appSettings>
    Line 7: <system.web>
    Line 8:


    Source File: E:\web\villagecirc\htdocs\Test\web.config Line: 6

    I though I was home free after I got the dang connection string to work does anyone know why I would get an error with this closing tag[?]



    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  8. quote:Originally posted by villagecirc

    for some odd reason I am getting an error on the closing tag


    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 6, position 5.

    Source Error:


    Line 4: <!-- add this kind of key -->
    Line 5: <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='e:\web\villagecirc\htdocs\_database\BT.mdb'/>
    Line 6: </appSettings>
    Line 7: <system.web>
    Line 8:


    Source File: E:\web\villagecirc\htdocs\Test\web.config Line: 6

    I though I was home free after I got the dang connection string to work does anyone know why I would get an error with this closing tag[?]




    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
    </blockquote id="quote"></font id="quote">

    not very odd ... you start the 'value' in your connectionstring with a double quote, but you are not closing that again ...

    change it to
     
  9. Your welcome ... if everybody would only read forums, they wouldn't last long I think

    --
    Steurm
    www.steurm.net/steurm
     
  10. [:)]I was finally able to get the dataset bound to a datagrid and I wanted to thank everyone for takeing the time to respond to my error messages. The first time doing something is always like pulling teeth to me but preseverence is the ...

    I had one more question are we able to update the data base using update commands delete commands and insert commands and so on?????[^]

    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
     
  11. Bruce

    Bruce DiscountASP.NET Staff

    Matthew,

    Yes. You should be able to do that.

    quote:Originally posted by villagecirc

    [:)]I was finally able to get the dataset bound to a datagrid and I wanted to thank everyone for takeing the time to respond to my error messages. The first time doing something is always like pulling teeth to me but preseverence is the ...

    I had one more question are we able to update the data base using update commands delete commands and insert commands and so on?????[^]

    Matthew H. Paulson
    [email protected]
    http://www.villagecircle.net
    </blockquote id="quote"></font id="quote">
     
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