The ConnectionString property has not been initialized.

Posts   
 
    
softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 17-Nov-2009 16:09:57   

Hi guys,

I'm developing a Winforms application (C#, .NET 2.0) with VS 2008.

All of a sudden the designer tells me the The ConnectionString property has not been initialized. when I open one of my forms.

This is the corresponding call stack:

at System.Data.OleDb.OleDbConnection.PermissionDemand()
at System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteSingleRowRetrievalQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction, IEntityFields fieldsToFill, IFieldPersistenceInfo[] fieldPersistenceInfos)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformFetchEntityAction(IEntity entityToFetch, ITransaction containingTransaction, IPredicateExpression selectFilter, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
at eposbox2_DAL.DaoClasses.Lok_BenutzerDAO.FetchLok_BenutzerUsingUCBen_BenSl(IEntity entityToFetch, ITransaction containingTransaction, String ben_BenSl, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) in P:\SVN\Explidia\eposbox2\DAL\DaoClasses\Lok_BenutzerDAO.cs:line 67
at eposbox2_DAL.EntityClasses.Lok_BenutzerEntity.FetchUsingUCBen_BenSl(String ben_BenSl, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields) in P:\SVN\Explidia\eposbox2\DAL\EntityClasses\Lok_BenutzerEntity.cs:line 382
at eposbox2_DAL.EntityClasses.Lok_BenutzerEntity.FetchUsingUCBen_BenSl(String ben_BenSl) in P:\SVN\Explidia\eposbox2\DAL\EntityClasses\Lok_BenutzerEntity.cs:line 343
at eposbox2.BAL.Benutzer..ctor(String pBenSl) in P:\SVN\Explidia\eposbox2\APP\BAL\Benutzer.cs:line 245
at eposbox2.BAL.ApplicationManager..cctor() in P:\SVN\Explidia\eposbox2\APP\BAL\ApplicationManager.cs:line 92  

All I'm doing in Benutzer.cs line 245 is:

   public Benutzer(string pBenSl)
    {
        _Entity = new Lok_BenutzerEntity();
        _Entity.FetchUsingUCBen_BenSl(pBenSl);  <--- line 245

What I don't understand: this happens while I'm in design mode. On runtime everything is fine. And this stuff has not been a problem for weeks. Suddenly just appeared.

Has anybody experienced such a problem before?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 17-Nov-2009 21:46:57   

Is app.config still in the project and being copied to the correct folder on build...?

Matt

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 18-Nov-2009 02:11:08   

Hi Matt,

thanks for your reply!

Yes sure. The app.config is in the source code folder and contains a valid connection string.

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Main.ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=P:\SVN\Explidia\eposbox2\RUN\eposbox2.mdb;User Id=;Password=;Jet OLEDB:System Database=;Jet OLEDB:Database password="/>

On Build the app.config is automatically copied to the output folder (of course with a different name: eposbox2.exe.config). Everything is fine on runtime.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Nov-2009 06:27:03   

It's a design time thing. You are triggering lazy-loading on the constructor of the class. This should fix the situation:

public Benutzer(string pBenSl)
{
    if( !DesignMode ) 
    {
        _Entity = new Lok_BenutzerEntity();
        _Entity.FetchUsingUCBen_BenSl(pBenSl);
        ...
    }
}

Ref: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=13773&StartAtMessage=0&#76784

David Elizondo | LLBLGen Support Team
softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 19-Nov-2009 06:52:39   

Hi daelmo,

hm, that's interesting. And actually, I already tried to make sure I'm not executing that code while being in design mode.

However, I didn't use the <DesignMode> property, because the code that forces the error is not within a control but rather in a simple class. So instead I used the following code.

 public static bool IsDesignMode
{
   get
   {
      return (System.ComponentModel.LicenseManager.UsageMode ==System.ComponentModel.LicenseUsageMode.Designtime);
   }
}

public Benutzer(string pBenSl)
{
     if( !IsDesignMode ) 
    {
        _Entity = new Lok_BenutzerEntity();
        _Entity.FetchUsingUCBen_BenSl(pBenSl);
        ...
    }
}

But this didn't help much. I was still getting the design time exception.

What I really don't understand: As far as I can see the code in the <Benutzer> class is not related at all to the WinForm that fires the exception.

Benutzer is a member of a static class called ApplicationManager. The constructor of this class is the only place where I call the constructor of the Benutzer class.

static ApplicationManager()
{
    if (!IsDesignMode)
    {
        //Create Benutzer instance for the logged user
        AktuellerBenutzer = new Benutzer(WinUser.UserName);
    }
}

As you can see I wrapped the call to the Benutzer constructor with <!IsDesignMode> again.

So the question is: maybe my IsDesignMode method just does not work?

Anyways: I understand this is not an LLBL issue in the proper sense. But if any of you guys had another ti I would very much appreciate this. Working on this form is becoming really annoying...

Thanks so much!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Nov-2009 10:32:42   

Instead of your IsDesignMode property please try the windows forms DesignMode property as David showed.

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 20-Nov-2009 06:14:36   

Is there a chance to use the windows forms <DesignMode> property within a class that is not a control?

As I already wrote, that was the only reason why I had to write my own <IsDesignMode> property. But maybe I'm missing something?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 20-Nov-2009 10:50:33   

Your class must have been used from within a control or a form, that where you should pass the value of Component.DesignMode to the class, maybe through the CTor of the class.

Bottom line, you should find a way to read this value or pass it to the class.

softwarea
User
Posts: 57
Joined: 05-Mar-2007
# Posted on: 21-Nov-2009 03:59:02   

Thanks guys! It's working again. Component.DesignMode did the trick.