custom connection string DataAccessAdapter in web application

Posts   
 
    
braidiano
User
Posts: 40
Joined: 18-Nov-2006
# Posted on: 08-May-2008 12:41:31   

Hi,

LLBLGen Pro 2.5 (23rd April) DataAccessAdapter SQL Server 2005 ASP.NET (C#)

I need to provide a custom connection string and catalog/schema name on a user-basis in a Asp.Net web application.

I tried to write a custom MyDataAccessAdapter() class that inerhits from DataAccessAdapter(). The constructor was:


public MyDataAccessAdapter(): base.(myConnStr)
{
     this.CatalogNameOverwrite .....[etc...]
}

I set all my LLBLGenProDatasource2.DataAdapterTypeName ="....MyDataAccessAdapter, ...DataDBSpecific" (using LLBLGenProDatasource Configuration Window at design time in Visual Studio).

Visul Studio at Design time returns this error:


An Unhandled Exception has occured. MyDataAccessAdapter,[...complete namespace....] Could not be set on property AdapterTypeName

So it works at runtime but it doesn't work at design time in VS. disappointed I tried to restart Visual Studio, clean and rebuild solution but it didn't help.

Was my approach (write e custom class that inerhits from DataAccessAdapter()) wrong?

thanks Regards Davide

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-May-2008 15:27:20   

You don't need to do that.

  • First you should use CatalogName Overwrites section in the config file, with an empty new catalog name.

eg.

<configSections>
    <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" />
</configSections>

<sqlServerCatalogNameOverwrites>
    <add key="myDevCatalog" value="" />
</sqlServerCatalogNameOverwrites>
  • This will force the system to use the catalog name in the connection string.

  • And hence you may pass the connection string to the DataAccessAdapter CTor. (Which might differ based on the logged in user).

braidiano
User
Posts: 40
Joined: 18-Nov-2006
# Posted on: 08-May-2008 15:35:50   

Hi Walaa,

I knew this solution, but it didn't help my needs, because I need to change the connectionstring and catalog name at runtime and not in web.config, because in web.config I don't know the logged user simple_smile

  • And hence you may pass the connection string to the DataAccessAdapter CTor. (Which might differ based on the logged in user).

How can I set the connectionstring in DataAccessAdapter CTor using LLBLGenProDataSoruce(2) with LivePersistence = ON ?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-May-2008 15:40:01   

And this is the correct solution for your case.

  • In the config file you will write an empty string for the catalog name.

  • Then at runtime you should pass the correct connection string to the DataAccessAdapter CTor.

  • For the LLBLGenProDataSource, just set its AdapterToUse property with an instance of the DataAccessAdapter instantiated with the needed ConnectionString.

braidiano
User
Posts: 40
Joined: 18-Nov-2006
# Posted on: 08-May-2008 16:18:14   

Thanks you for your reply.

using your solution I need set for each page and for each LLBLGenProDataSource2 contained on the page, the AdapterToUse property and manual instancing the adatper.

If i forget to set the property the LLBLGenProDataSource2 uses the "self-instanced Adapter" and this will make some mistakes confused

As I wrote in first post my solutions works properly at runtime.. the issue is only at design time in Visual Studio.

I attach a screenshoot.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-May-2008 10:23:19   

using your solution I need set for each page and for each LLBLGenProDataSource2 contained on the page, the AdapterToUse property and manual instancing the adatper.

If i forget to set the property the LLBLGenProDataSource2 uses the "self-instanced Adapter" and this will make some mistakes

Please check the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12045

As I wrote in first post my solutions works properly at runtime.. the issue is only at design time in Visual Studio.

This issue was reported before, here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10249 And it worked out by itself, most probably a VS designer issue.

Another relevant thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7802

braidiano
User
Posts: 40
Joined: 18-Nov-2006
# Posted on: 09-May-2008 10:43:10   

Thank you for all replies.

I solved the problem by setting some conditions block in MyDataAccessAdapter, and putting all code thats instance the DataAccessAdapter inside them.



if(HttpContext != null)
{
   ...........
}

so, now at design mode it works.

The issue seems caused due to assembly loading probelm in VS 2005 at design time.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 09-May-2008 10:44:17   

Thanks for the feedback.