ADO.net: Error "The ConnectionString property has not been initialized. "

T

Tony

Dear All,
When I run an example program on the
http://www.dotnetjunkies.com/quicks...a/datagrid1.src&file=VB\datagrid1.aspx&font=3

I received an 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 11: Line 12: DataSet ds = new DataSet();Line 13:
myCommand.Fill(ds, "Authors");Line 14: Line 15:
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;"Can you tell me
what's wrong? Thanks!
The example code is below:
======================

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "Authors")
MyDataGrid.DataSource=ds.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana">Simple Select to a DataGrid Control</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</body>
</html>
 
M

Miha Markic [MVP C#]

Hi Tony,

I guess that you are passing an empty connection string.
See what contains MyConnection.ConnectionString or what returns
System.Configuration.ConfigurationSettings.AppSettings("PubsSt

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Tony said:
Dear All,
When I run an example program on the
http://www.dotnetjunkies.com/quicks...a/datagrid1.src&file=VB\datagrid1.aspx&font=3

I received an 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 11: Line 12: DataSet ds = new DataSet();Line 13:
myCommand.Fill(ds, "Authors");Line 14: Line 15:
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;"Can you tell me
what's wrong? Thanks!
The example code is below:
======================

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "Authors")
MyDataGrid.DataSource=ds.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana">Simple Select to a DataGrid Control</font></h3>
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</body>
</html>
 
T

Tony

It works!!



After I used the following connection string:



¡°workstation id='sha-tongl-xp1';uid=sa;pwd='';server=localhost;initial
catalog='Pubs'¡±



I really appreciated your help. Have a nice day!

Miha Markic said:
Hi Tony,

I guess that you are passing an empty connection string.
See what contains MyConnection.ConnectionString or what returns
System.Configuration.ConfigurationSettings.AppSettings("PubsSt

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Tony said:
Dear All,
When I run an example program on the
http://www.dotnetjunkies.com/quicks...a/datagrid1.src&file=VB\datagrid1.aspx&font=3
I received an 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 11: Line 12: DataSet ds = new DataSet();Line 13:
myCommand.Fill(ds, "Authors");Line 14: Line 15:
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;"Can you tell me
what's wrong? Thanks!
The example code is below:
======================

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "Authors")
MyDataGrid.DataSource=ds.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<body>
<h3><font face="Verdana">Simple Select to a DataGrid
Control said:
<ASP:DataGrid id="MyDataGrid" runat="server"
Width="700"
BackColor="#ccccff"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
EnableViewState="false"
/>
</body>
</html>
 

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

Top