ASP.NET Connection String Adapter

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 04-Feb-2008 18:11:27   

Adapter, VS 2008, .NET 3.5

HelloWorld App.

What's the recommended best practice for setting the LLBLGenProDataSource2 's Adapter's ConnectionString?

Currently I do something like this:


        protected void Page_Load(object sender, EventArgs e)
        {
           if(!this.IsPostBack)
           {
               mainBinder.AdapterToUse.ConnectionString = userConnectionString;
           }
        }

Can it be set some way in the Global.ascx perhaps?

I could also just create a class which inherits from LLBLGenProDataSource2 and knows how to get its connectionstring.

Ian

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 04-Feb-2008 18:23:18   

the best way is adding it in your app.config or web.config see below:

<?xml version="1.0"?> <configuration> <appSettings> <add key="Main.ConnectionString" value="data source=.;initial catalog=Northwind;integrated security=SSPI;persist security info=False;packet size=4096"/> </appSettings> </configuration>

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 04-Feb-2008 18:26:14   

I forgot to mention that the connection string is calculated dynamically and is user-specific.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Feb-2008 10:49:22   

I think you should create an instance of the Adapyter first then set its connection string and then associate it with the LLBLGen DataSource.

        protected void Page_Load(object sender, EventArgs e)
        {
         if(!this.IsPostBack)
         {
             DataAccessAdpater adapter = new DataAccessAdapter();
             adapter.ConnectionString = userConnectionString;
             mainBinder.AdapterToUse = adapter;
         }
        }