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();
}
}
}
}
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();
}
}
}
}