ASP.net: Error "Exception Details: System.InvalidOperationException: The ConnectionString property h

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

Martin Marinov

do you have a web.config file with these lines

<appSettings>
<add key="PubsString" key="your connectionstring here" />
</appSettings>

Regards
Martin
 
T

Tony

Thank you for your help.

There is no such paragragh in the web.config file. Which place i can add
these lines into this file?

Martin Marinov said:
do you have a web.config file with these lines

<appSettings>
<add key="PubsString" key="your connectionstring here" />
</appSettings>

Regards
Martin


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>
 
M

Martin Marinov

your web.config must have such structure

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.web>

.....

</system.web>

<appSettings>

<add key="PubsString" key="your connectionstring here" />

</appSettings>

</configuration>

Regards
Martin


Tony said:
Thank you for your help.

There is no such paragragh in the web.config file. Which place i can add
these lines into this file?

Martin Marinov said:
do you have a web.config file with these lines

<appSettings>
<add key="PubsString" key="your connectionstring here" />
</appSettings>

Regards
Martin
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
 
T

Tony

Dear Martin,

Thak you for your quick reply.I am sorry for interrupt you again,

I have added the following lines into the web.config file,

<appSettings>
<add key="PubsString" value="Provider='sqloledb';Initial Catalog='Pubs';
uid='v-tleung';pwd='Mynameis@01'">
</add>
</appSettings>

but i recieved the following error:

"Exception Details: System.ArgumentException: Keyword not supported:
'provider'.

Source Error:
Line 11: Dim MyCommand As SqlDataAdapter
Line 12:
Line 13: MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
Line 14: MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
Line 15:

I have installed Sql Server on my localhost. How can we compose the
ConnectionString. Does this program work well on your side?

Martin Marinov said:
your web.config must have such structure

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.web>

....

</system.web>

<appSettings>

<add key="PubsString" key="your connectionstring here" />

</appSettings>

</configuration>

Regards
Martin


Tony said:
Thank you for your help.

There is no such paragragh in the web.config file. Which place i can add
these lines into this file?
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
 
M

Martin Marinov

Well, because of using sql client you can not use the oledb provider
try using this connection string :

workstation id=your_computer_name;packet size=4096;user id=v-tleung;data
source=your_sql_server;persist security info=False;initial catalog=Pubs;
Password=Mynameis@01;

if your sql server is installed locally for data source put : localhost

you can see here all of possible connection strings :
http://www.connectionstrings.com/

Regards
Martin

Tony said:
Dear Martin,

Thak you for your quick reply.I am sorry for interrupt you again,

I have added the following lines into the web.config file,

<appSettings>
<add key="PubsString" value="Provider='sqloledb';Initial Catalog='Pubs';
uid='v-tleung';pwd='Mynameis@01'">
</add>
</appSettings>

but i recieved the following error:

"Exception Details: System.ArgumentException: Keyword not supported:
'provider'.

Source Error:
Line 11: Dim MyCommand As SqlDataAdapter
Line 12:
Line 13: MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
Line 14: MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
Line 15:

I have installed Sql Server on my localhost. How can we compose the
ConnectionString. Does this program work well on your side?

Martin Marinov said:
your web.config must have such structure

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<system.web>

....

</system.web>

<appSettings>

<add key="PubsString" key="your connectionstring here" />

</appSettings>

</configuration>

Regards
Martin
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
 
T

Tony

Dear Martin,



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 wonderful day!



Martin Marinov said:
Well, because of using sql client you can not use the oledb provider
try using this connection string :

workstation id=your_computer_name;packet size=4096;user id=v-tleung;data
source=your_sql_server;persist security info=False;initial catalog=Pubs;
Password=Mynameis@01;

if your sql server is installed locally for data source put : localhost

you can see here all of possible connection strings :
http://www.connectionstrings.com/

Regards
Martin

Tony said:
Dear Martin,

Thak you for your quick reply.I am sorry for interrupt you again,

I have added the following lines into the web.config file,

<appSettings>
<add key="PubsString" value="Provider='sqloledb';Initial Catalog='Pubs';
uid='v-tleung';pwd='Mynameis@01'">
</add>
</appSettings>

but i recieved the following error:

"Exception Details: System.ArgumentException: Keyword not supported:
'provider'.

Source Error:
Line 11: Dim MyCommand As SqlDataAdapter
Line 12:
Line 13: MyConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsSt
ring"))
Line 14: MyCommand = New SqlDataAdapter("select * from Authors",
MyConnection)
Line 15:

I have installed Sql Server on my localhost. How can we compose the
ConnectionString. Does this program work well on your side?
http://www.dotnetjunkies.com/quicks...a/datagrid1.src&file=VB\datagrid1.aspx&font=3 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
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top