简体   繁体   中英

Using SMO to call Database.ExecuteNonQuery() concurrently?

I have been banging my head against the wall trying to figure out how I can run update scripts concurrently against multiple databases in a single SQL Server instance using SMO. Our environments have an ever-increasing number of databases which need updating, and iterating through one at a time is becoming a problem (too slow).

From what I understand SMO does not support concurrent operations, and my tests have bore that out. There seems to be shared memory at the Server object level, for things like DataReader context, keeps throwing exceptions such as "reader is already open." I apologize for not having the exact exceptions I am getting. I will try to get them and update this post.

I am no expert on SMO and just feeling my way through to be honest. Not really sure I am approaching it the right way, but it's something that has to be done, or our productivity will slow to a crawl.

So how would you guys do something like this? Am I using the wrong technology with SMO? All I am wanting to do is execute sql scripts against databases in a single sql server instance in parallel.

Thanks for any help you can give, Daniel

Just use multiple ServerConnection objects, and instantiate multipe Server objects with each. Basically, one per thread. It doesn't matter if they all connect to the same database instance.

I have written an application to document the schema of a database that way. I run multiple "queries" (not just ExecuteNonQuery() but also other functions upon SMO) concurrently without any issues - well, at least until today. Unfortunately their doesn't seem to be much documenation on SMO apart from rather "basic" stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM