开发者

add connection string without using app.config

开发者 https://www.devze.com 2023-01-06 16:51 出处:网络
i created a data access layer dll using subsonic. however it uses the connectionstring from the app.config.

i created a data access layer dll using subsonic. however it uses the connectionstring from the app.config. i am using it in ninjatrader and dont want to mess around w开发者_开发百科ith the ninjatrader app.config for the connecitonstring. how do i avoid this issue.


I believe the best you can hope for here is to use a separate file for the connection strings:

in app.config

<connectionStrings ConfigSource="myConnStr.config" />

in myConnStr.config:

<connectionStrings > 
  <add .... />
  <add .... />
</connectionStrings > 


I believe you can set it at runtime using the SetDefaultConnectionString method:

SubSonic.DataService.GetInstance("InstanceName").SetDefaultConnectionString("ConnectionString");


Sample how to programatically hardcode connectionstring:

string connectionString = string.Format(@"Data Source={0}", Path.Combine(this.ConfigFolder, ConfigDb));
string providerName = @"System.Data.SQLite";
var provider = ProviderFactory.GetProvider(connectionString, providerName);
_configRepo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);

This sample use sqlite database which is located in this.ConfigFolder. ConfigDB contains name of a database file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号