Default value in datagridview from other table

Posts   
 
    
Pisang
User
Posts: 4
Joined: 24-Mar-2006
# Posted on: 24-Mar-2006 11:35:14   

Hello,

we are using: VB.Net SelfServicing, two class scenario LLBLGen 1.0.2005.1 ORMSupportClasses.NET20.dll version 1.0.20051.51027 Visual Studio 2005: V8.0.50727.42

Here is the problem: In VS we have a DataGridView; the datasource of this DataGridView is an BindingSource; this BindingSource is connected to an Collection from llblgen.

In this dataGridView there is also an DataGridViewComboBoxColumn this ComboBox has also an BindingSource as Datasource an is connected to an Collection from llblgen

All of this is just working fine so far.

When we click in runtime on de datagridview to make a new row the ComboBox wants an default value, oke we set this value in InitClassEmpty in the Entitybase. But when we wants this value to come from an other table in de database we get an error in de design mode in VS (The key 'Main.ConnectionString' does not exist in the appSettings configuration section.) and then we have no visual design any more.

the code in InitClassEmpty:


 ' __LLBLGENPRO_USER_CODE_REGION_START InitClassEmptyme.

            If Fields.State = EntityState.New Then
                Dim ArtikelEenheidInkoop As New ArtikelEenheidCollection
                ArtikelEenheidInkoop.GetMulti(Nothing)
                Me.IdArtikelEenheid = ArtikelEenheidInkoop.Item(0).IdArtikelEenheid             
            End If

' __LLBLGENPRO_USER_CODE_REGION_END

What a we doing wrong?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Mar-2006 16:11:18   

Do you have the 'Main.ConnectionString' key defined in your web.config (for web application) or applicationName.config file inside the appSettings configuration section?

Pisang
User
Posts: 4
Joined: 24-Mar-2006
# Posted on: 24-Mar-2006 16:28:59   

this is my app.config


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <appSettings>
    <add key="Main.ConnectionString" value="data source=xxx;initial catalog=xxx;User ID=xxx;Password=xxx;persist security info=False;packet size=4096"/>
  </appSettings>
</configuration>

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 25-Mar-2006 01:32:23   

Are there any other projects that you could be referencing that access the database and need this setting?

Pisang
User
Posts: 4
Joined: 24-Mar-2006
# Posted on: 27-Mar-2006 08:50:55   

No this is the only project that is referencing and need this setting.


                ArtikelEenheidInkoop.GetMulti(Nothing)

If we delete this line off code in the InitClassEmpty then the error is disappeared.

Is 't to 'early' for VS to do this in de design mode?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 28-Mar-2006 16:01:34   

At design time, vs.net 2005 secretly adds and removes a new entity to find out the properties of the contained object. This then triggers your load action which fails because the connection string can't be read (there's no .config file).

Frans Bouma | Lead developer LLBLGen Pro
Pisang
User
Posts: 4
Joined: 24-Mar-2006
# Posted on: 28-Mar-2006 16:32:24   

That’s the problem indeed.

Solution: We have copied the appSetting key with the connection string to the devenv.exe.config located: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE (on our pc)

Do not forget the set this value back at the end of the project.

If there is a better sollution please tell us.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 29-Mar-2006 11:10:29   

Pisang wrote:

That’s the problem indeed.

Solution: We have copied the appSetting key with the connection string to the devenv.exe.config located: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE (on our pc)

Do not forget the set this value back at the end of the project.

If there is a better sollution please tell us.

I don't have a proper solution, I'm afraid. The entity doesn't know in which collection it is added, so it can't check if the containing collection's Site property is null or not (it's not null if in design mode, which is pretty much the only way to check it). Then it would be possible to set DbUtils.ActiveConnectionString to a value which makes sense. This can also be done to an override of AddNew in the entitycollection, however that's also not that appealing, as it's code you don't need at runtime.

Btw, the routine you have in the init routine, isn't that pretty inefficient for just fetching 1 value? Couldn't you better use a GetScalar() with a filter ? Not that that helps in your situation.

I could wrap the DbUtils routine which reads the connection string into a try/catch, swallow the exception and later on make the connection using code simply don't do anything if the connection fails to open. However that would bypass signals which are essential for finding bugs earlier, so I can't do that.

Frans Bouma | Lead developer LLBLGen Pro