none
The ConnectionString property has not been initialized. 'System.InvalidOperationException'

    Question

  • Hi,

    Following exception is being thrown on a particular user desktop only while initiating the application.

    Let me know if any one of you knows the workaround for this exception:

    Message: HandlingInstanceID: c48656c1-2793-4cab-b379-e1aeaffd9340

    An exception of type 'System.InvalidOperationException' occurred and was caught.

    --------------------------------------------------------------------------------

    03/08/2007 10:55:42

    Type : System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    Message : The ConnectionString property has not been initialized.

    Source : System.Data

    Help link :

    Data : System.Collections.ListDictionaryInternal

    TargetSite : Void PermissionDemand()

    Stack Trace : at System.Data.SqlClient.SqlConnection.PermissionDemand()

    at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)

    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

    at System.Data.SqlClient.SqlConnection.Open()

    at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

    at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)

    at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

     

    Thursday, March 08, 2007 5:54 AM

All replies

  • It's a bit hard to go on the little details you've provided.

    The PermissionDemand() in there together with the fact this only happens on one desktop suggests that there is a permissions problem somewhere.

    Is the user that is getting this problem running as local admin or just a standard user? If a standard user, does an domain admin get the same problem?

    Thursday, March 08, 2007 10:23 AM
  • Hi Alan,

    Thanks for your response. I tracked down the problem myself and identified this with an issue within the registry entries being added when you create a System DSN using ODBC Data Source.

    Earlier my application (client/server) used to fetch the connection string thru app.config and to make it more generic and independant of any changes being required to be made to app.config we decided to form the connection string by fetching the DSN entries being created in the local registry.

    We basically decided to fetch the 'Database' and the 'Server' keys from the registry to form the string. But, when you specify windows authentication as your mode of authentication while creating the DSN it does not create a KEY - 'Database' within your registry. It creates it only when you choose SQL Server (we are using SQL Server 2005) authentication.

    I didn't understood the logic behind this though?

     

     

     

     

    Sunday, March 11, 2007 5:33 AM
  • I am having the same problem but I didn't understand a word you just said. I am obviously a little new at this, but I try to figure most things out first by reading other post, hence why I am here. But this one is just over my head. the source code is as follows, thanks in advance.

    Imports System.Data.OleDb

    Public Class Form1

    Dim theOleDbCommand As New OleDbCommand()

    Dim theOleDbDataAdapter As New OleDbDataAdapter(theOleDbCommand)

    Dim theDataSet As New DataSet()

     

     

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'TODO: This line of code loads data into the 'Db2DataSet.Customers' table. You can move, or remove it, as needed.

    Me.CustomersTableAdapter.Fill(Me.Db2DataSet.Customers)

    End Sub

    Private Sub InsertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InsertButton.Click

    Me.theOleDbCommand = New OleDbCommand("SELECT * FROM table", New OleDbConnection())

    Me.theOleDbDataAdapter = New OleDbDataAdapter(Me.theOleDbCommand)

    Me.theDataSet = New DataSet()

    Me.CustomersTableAdapter.Fill(Me.Db2DataSet.Customers)

    ------------- Me.theOleDbCommand.Connection.Open() ---------------------- Here is where the error occures, I am sure there will be more with the theOleDbCommand.Connection but can't get there yet.

    Me.theOleDbDataAdapter.Fill(Me.theDataSet)

    Me.theOleDbCommand.Connection.Close()

    Me.DataGridView1.DataSource = Me.theDataSet.Tables(0).DefaultView

    End Sub

     

    Private Sub RefreshDataset()

    Me.CustomersTableAdapter.Fill(Me.Db2DataSet.Customers)

    End Sub

     

    Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click

    Me.theOleDbCommand = New OleDbCommand("SELECT * FROM table", New OleDbConnection())

    Me.theOleDbDataAdapter = New OleDbDataAdapter(Me.theOleDbCommand)

    Me.theDataSet = New DataSet()

    Me.theOleDbCommand.Connection.Open()

    Me.theOleDbDataAdapter.Update(Me.theDataSet)

    Me.theOleDbCommand.Connection.Close()

     

    End Sub

    End Class

    this is just a sample app that I am working with, I will eventually use it integrated with a user input form, if at all possible. I have the other app made, it is like a time card application. Just thought I would try a sample first and can't get it. I don't know if any of that helped.

    Friday, March 16, 2007 4:29 PM
  • i was facing the same issue while troubleshooting someone's code. but in my case, the code was written in a way that it was entering the transaction, execute some code, commit transaction, and execute some other code without exiting the transaction.

    when i moved my code inside the transaction it worked fine.

    hope this helps if u r having same issue.

    Thursday, July 28, 2011 6:50 PM
  • guys...Please stop speculating on this like MVPs.....:))))))))))))))))), 

    I could reproduce with a strong point, If there is an exception occurred, if you have rolled back your transaction, and try to continue the further data retrieval, Connection is Closed, so the error. 

    if you want more details about your bug, In VS IDE, keep exception ON. ( Debug --> Exceptions, check on exceptions... )you would see the dirty code which causing this error !

    Hydtechie

    HydPhani

    Monday, July 22, 2013 12:19 PM