ConnectionString property has not been initialized error

Posts   
 
    
Abrar
User
Posts: 26
Joined: 13-Nov-2009
# Posted on: 26-Jan-2010 17:54:32   

llblgen 2.5,adapter,sql server 2005,C# 3.5

I am getting the above error whn i am trying to connect with database. I have DataAdapter, DataAdapterDBSpecific, SD.LLBLGen.Pro.DQE.SQLServer.NET, SD.LLBLGen.Pro.ORMSupportClass.NET in the References. I have a App.config <configuration> <appSettings> <add key="Main.ConnectionString" value="data source=PLSSQL-qmf-010;initial catalog=Billing;User ID=Billing;Password=billing;persist security info=False;packet size=4096"/> </appSettings>

While debugging i found the ReadConnectionStringFromConfig() method is returning a empty string, and ConnectionStringKeyName as Main.ConnectionString, which is correct.

Its working fine when i am specifying the connectionString like this in Adapter("data source=PLSSQL-qmf-010;initial catalog=Billing;User ID=Billing;Password=billing;persist security info=False;packet size=4096")

I dont know i am doing wrong. but for sure i am missing something..

Thanks for your help in advance. Ali

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 26-Jan-2010 20:49:02   

Have you moved the app.config file from the project where it was generated to the calling application, or at least copied the relevant sections from it in to the calling application's app.config ?

Matt

Abrar
User
Posts: 26
Joined: 13-Nov-2009
# Posted on: 26-Jan-2010 22:04:06   

Yes, i copied the relevant sections from DatabaseSpecific to the calling application's app.config. This is the message of my 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.QuietOpen(IDbConnection connection, ConnectionState& originalState) 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) at RetailGasBilling.DataAdapter.DatabaseSpecific.DataAccessAdapter.CallRetrievalStoredProcedure(String storedProcedureToCall, SqlParameter[] parameters, DataTable tableToFill) in C:\CNEProjects\RetailGasBilling\Invoice Review Process\DatabaseSpecific\DataAccessAdapter.cs:line 238 at RetailGasBilling.DataAdapter.DatabaseSpecific.RetrievalProcedures.GetReviewGroup(DataAccessAdapter adapter) in C:\CNEProjects\RetailGasBilling\Invoice Review Process\DatabaseSpecific\RetrievalProcedures.cs:line 240 at InvoiceReview.Workflow.InvoiceReviewWorkflow.getAllGroups() in C:\CNEProjects\RetailGasBilling\Invoice Review Process\Source\RetailGasBilling.InvoiceReview\InvoiceReview.Workflow\InvoiceReviewWorkflow.cs:line 43

MTrinder wrote:

Have you moved the app.config file from the project where it was generated to the calling application, or at least copied the relevant sections from it in to the calling application's app.config ?

Matt

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 26-Jan-2010 23:03:35   

And is app.config definitly getting copied and renamed to the build folder when you build your application ?

Does the app.config have a seperate <connectionStrings> section as well as the <appSettings> ?

Do you get the same issue if you run the compiled version outside of visual studio ?

Matt

Abrar
User
Posts: 26
Joined: 13-Nov-2009
# Posted on: 27-Jan-2010 16:13:40   
  1. And is app.config definitly getting copied and renamed to the build folder when you build your application ?

Yes, the app.config is getting copied to my build folder (bin\Debug\InvoiceReview.Workflow.dll.config)

  1. Does the app.config have a seperate <connectionStrings> section as well as the <appSettings> ?

No, I just have <appSettings>

Do you get the same issue if you run the compiled version outside of visual studio ?

Yes

Thanks, Ali

MTrinder wrote:

And is app.config definitly getting copied and renamed to the build folder when you build your application ?

Does the app.config have a seperate <connectionStrings> section as well as the <appSettings> ?

Do you get the same issue if you run the compiled version outside of visual studio ?

Matt

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Jan-2010 17:13:06   

\InvoiceReview.Workflow.dll.config

.config files only work for .exe applications - .dll files do not automatically read them

Do you have a calling application which runs your whole process ? It is the app.config file for this that needs to contain the connection string settings.

Matt