views:

123

answers:

3

Hi,
I'm facing currently a problem regarding Subsonic configuration.

What I want to achieve is using subsonic data access in a System.Web.UI.Design.ControlDesigner class.

This class is hosted in Visual Studio Environment and enables design time operations on the attached System.Web.UI.WebControls.Control.

The only problem is SubSonic seems always looking for SubSonicSection in the application configuration regardless passing connection string to it.

The relevant code snippet:

using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(new SqlDataProvider(), ConnectionString))
{
Table1 _table1 = new Select().From<..().Where(...).IsEqualTo(...).ExecuteSingle<...>();

Throws exception on ExecuteSingle() method (configuration section was not found)

while

using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(ConnectionString))
{

Throws exception on new SharedDbConnectionScope() (configuration section was not found)

So the question is:
Is there any way to pass the settings runtime to bypass the configuration section lookup as I don't want to add any subsonic specific configuration to devenv.configuration

Thanks

A: 

I don't think you can do this in 2.x without customising the templates (which can obviously give support issues when a newer version of SubSonic is released).

Sorry, don't know about 3.0

kevinw
A: 

I'm assuming you're using SubSonic 2.x based on your query syntax. Have a look at the following two forum posts which should point you in the right direction. What you're trying to do is possible, in fact SubCommander does exactly this, download the source and have a look at the SetProviderManually() method.

http://forums.subsonicproject.com/forums/t/1617.aspx

http://forums.subsonicproject.com/forums/t/1502.aspx

Adam
that was the solution, thanks
csizo
A: 

The method to use Subsonic runtime provider configuration:

(example):

private void SetSubsonicProviderManually(string ConnectionString)  
{
//clear the providers and reset  
DataService.Provider = new SqlDataProvider();  
DataService.Providers = new DataProviderCollection();  

//instance a section - we'll set this manually for the DataService  
SubSonicSection section = new SubSonicSection();  
section.DefaultProvider = __SubsonicProviderName__;  

//set the properties
DataProvider provider = DataService.Provider;  
NameValueCollection config = new NameValueCollection();  

//need to add this for now  
config.Add("connectionStringName", __ConnectionString__);  

//initialize the provider  
provider.Initialize(__SubsonicProviderName__, config);  

provider.DefaultConnectionString = ConnectionString;  

DataService.Providers.Add(provider);  

}
csizo