C# visual studio设计主机中的亚音速
我目前面临一个关于亚音速配置的问题 我想要实现的是在System.Web.UI.Design.ControlDesigner类中使用亚音速数据访问 此类托管在Visual Studio环境中,并在附加的System.Web.UI.WebControl.Control上启用设计时操作 唯一的问题是亚音速似乎总是在应用程序配置中寻找亚音速部分,而不管是否将连接字符串传递给它 相关代码段:C# visual studio设计主机中的亚音速,c#,visual-studio,subsonic,app-config,C#,Visual Studio,Subsonic,App Config,我目前面临一个关于亚音速配置的问题 我想要实现的是在System.Web.UI.Design.ControlDesigner类中使用亚音速数据访问 此类托管在Visual Studio环境中,并在附加的System.Web.UI.WebControl.Control上启用设计时操作 唯一的问题是亚音速似乎总是在应用程序配置中寻找亚音速部分,而不管是否将连接字符串传递给它 相关代码段: using (SharedDbConnectionScope dbScope = new SharedDbCon
using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(new SqlDataProvider(), ConnectionString))
{
Table1 _table1 = new Select().From<..().Where(...).IsEqualTo(...).ExecuteSingle<...>();
未找到新SharedDbConnectionScope配置节上的引发异常
因此,问题是:
由于我不想向devenv.configuration添加任何亚音速特定的配置,有没有办法通过设置运行时绕过配置部分查找
谢谢我认为在2.x中,如果不自定义模板,就无法做到这一点,因为当发布新版本的亚音速时,模板显然会出现支持问题
对不起,我不知道关于3.0的情况,我假设您使用的是基于查询语法的亚音速2.x。看看下面的两个论坛帖子,它们会为你指明正确的方向。您试图做的是可能的,实际上Subcander正是这样做的,下载源代码并查看SetProviderManually方法
使用亚音速运行时提供程序配置的方法: 例如:
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);
}
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);
}