Not Initialized...

G

Guest

I have the following error using vs.net 2003 C#:

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:

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.SqlClient.SqlConnection.Open()
SDM.WebForm1.Button1_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032
________________________________________________

My code is:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Data.OleDb;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace SDM
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{

protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#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.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

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

try
{
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.Open();
System.Data.SqlClient.SqlCommand sqlInsert1 = new SqlCommand(@" USE SDM
Bulk INSERT dbo.tbl_client FROM 'D:\client.txt' WITH ( FIELDTERMINATOR = ','
,ROWTERMINATOR = '\n') ");
System.Data.SqlClient.SqlCommand sqlInsert2 = new SqlCommand(@" USE SDM
Bulk INSERT dbo.tbl_master FROM 'D:\master.txt' WITH ( FIELDTERMINATOR = ','
,ROWTERMINATOR = '\n') ");
System.Data.SqlClient.SqlCommand sqlDelete = new SqlCommand("DELETE FROM
tbl_Client FROM tbl_master" + "WHERE tbl_master.Phone = tbl_Client.Phone");

if (sqlDelete.ExecuteNonQuery() > 0)
{
Label1.Text = "Record has been sucessfully deleted!";



}
else
{
Label1.Text = "Sorry, could not access database";
}
}
finally
{
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.Close();
}
}
}
}
 
T

Tod Birdsall

Hi,

The SqlConnection class has a ConnectionString property that needs to
be set before you can call the Open() method. The connection string
will depend on your SQL Server settings, but may look similart to this:

"user id=sa; password=myPassword; data source=myServer; initial
catalog=northwind;"

You can find a more detailed explanation of the ConnectionString
property here:
http://tinyurl.com/69g4r

Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com
 
J

Joyjit Mukherjee

Hi,

Initialize the connectionstring property of the connection object (see more
in www.connectionstrings.com), then assign the connection object to the
command object (more on
http://msdn.microsoft.com/library/d...rfsystemdatasqlclientsqlcommandclasstopic.asp)

HTH

Regards
Joyjit

lornejones said:
I have the following error using vs.net 2003 C#:

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:

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.SqlClient.SqlConnection.Open()
SDM.WebForm1.Button1_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top