Showing posts with label connecting. Show all posts
Showing posts with label connecting. Show all posts

Monday, March 26, 2012

The connections current state is Connecting.

Only on one page that I got in my project do I get this error:

ExecuteReader requires an open and available Connection. The connection's current state is Connecting.

Shouldn't the connection object automatically wait until it's open and then move on ?

The code:


Dim SQL As String, MyRead As OleDb.OleDbDataReader

Try
MyConn = New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("ConnectionString"))
If MyConn.State <> ConnectionState.Open Then
MyConn.Open()
End If
Try
SQL = "SELECT * FROM tbl_table"
Dim MyCMD As New OleDb.OleDbCommand(SQL, MyConn)
MyRead = MyCMD.ExecuteReader
MyCMD.Dispose()
If Not MyRead.Read = False Then
LN = MyRead.GetString(0)
FN = MyRead.GetString(1)
EML = MyRead.GetString(2)
PHN = MyRead.GetString(3)
ADD = MyRead.GetString(4)
CITY = MyRead.GetString(5)
STATE = MyRead.GetString(6)
ZIP = MyRead.GetString(7)
COUNTRY = MyRead.GetString(8)
FAX = MyRead.GetString(9)
CELL = MyRead.GetString(10)
URL = MyRead.GetString(11)
COMPANY = MyRead.GetString(12)
End If
Catch ex As Exception
Call READ_EXCEPTION(ex)
Finally
MyRead.Close()
End Try
Catch ex As Exception
Call READ_EXCEPTION(ex)
Finally
MyConn.Dispose()
End Try

Have you stepped through the code to find out if it's executing the myConn.Open method?
Not yet, the thing is that I can just refresh the page and it will start loading normally, it will do this completely at random.

The ConnectionString property has not been initialized

Hi, I am trying to run some code I got off from the Quickstart tutorial for connecting to an Access database. I have been attempting several different methods from several different tutorials, none of which have been successful.

Here is the code that I have used which gave me the error: "The ConnectionString property has not been initialized" The complete error message is posted below the code.


<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. 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("PubsString"))
MyCommand = New SqlDataAdapter("select * from Release_of_Information", MyConnection)

DS = new DataSet()
MyCommand.Fill(ds, "Release_of_Information")

MyDataGrid.DataSource=ds.Tables("Release_of_Information").DefaultView
MyDataGrid.DataBind()
End Sub

</script

Below is the complete error message.

I made a change to the web.cnfg file, as is stated below, and all that I got was even less functionality (okay, no functionality) from the webserver.

any ideas ?

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:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@dotnet.itags.org. Page Language="C#" Debug="true" %
or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configurationTry adding a Trace.Write (or a response.write) to see what your application sees as the configuration string - like:
Trace.Write("Config = " & ConfigurationSettings.AppSettings("PubsString"))

see what's really happening there - - it looks like, at first glance, that it merely doesn't find a viable connection string there.
Check out this link:

http://www.connectionstrings.com/
With my code now looking like this:

<configuration>
<appSettings>
<add key="PubsString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\C:\mikep\Career_Start\Career_Start.mdb;User Id=admin;Password=;" />
</appSettings>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<%@dotnet.itags.org. Import Namespace="System.Data.SqlClient" %
<html>
<script language="VB" runat="server"
Sub Page_Load(Sender As Object, E As EventArgs)
Trace.Write("Config = " & ConfigurationSettings.AppSettings("PubsString"))
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))
MyCommand = New SqlDataAdapter("select * from Release_of_Information", MyConnection)

DS = new DataSet()
MyCommand.Fill(ds, "Release_of_Information")

MyDataGrid.DataSource=ds.Tables("Release_of_Information").DefaultView
MyDataGrid.DataBind()
End Sub

</script
<body

I am still getting "The ConnectionString property has not been initialized" error message.

I will be glad if I can get beyond this...
your code in web.config looks fine to me just check that you are using the same username and password as you have specified.

Also try changing this the following line:


MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))

TO

string ConnectionString = (string) ConfigurationSettings.AppSettings["PubsString"];
SqlConnection myConnection = new SqlConnection(ConnectionString);