开发者

Connections with many databases

We have a webapp where each client has their own db (approx. 700 at the moment).

In SubSonic 2, you had to wrap each call with the SharedDBConnectionScope passing in the right connection string to use, otherwise you ran the risk of one thread or client getting data from another thread or client.

In SubSonic3 is this still needed? Do I need to wrap the calls like I did in 2.x?

There are easy ways of switching the database now, but do开发者_运维知识库 I still have thread issues or can I do away with the call to SharedDBConnectionScope?


SubSonic 3 greatly improved the way to create a provider from scratch or just passing a name and a connectionsctring:

Some Examples:

// Linq Templates:
var db = new YourDB("connectionstring goes here", "System.Data.SqlClient");

// SimpleRepository without app.config
IDataProvider provider = SubSonic.DataProviders.ProviderFactory.GetProvider(
    connectionString: "Server=localhost;Database=clientdb;Uid=root;",
    providerName: "MySql.Data.MySqlClient"
);
IRepository repository = new SimpleRepository(provider,
    SimpleRepositoryOptions.RunMigrations);

So basically you can create a provider or repository each time a client connects and use this in your class.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜