How to run batch SQL file using c#?
I want to run a big set of SQL statements in one go in c#; this SQL also contains numerous local variables. I tried to run that SQL using ADO.Net but I got an exception:开发者_高级运维 "Cannot declare more than 10000 local variables". Can I run these SQL statements in a batch file (using c#) to avoid this exception/limitation? If yes, how? Is there any better approach?
I am using SQL Server 2008 R2 and C# 4.0.
Looking forward to assistance.
"Cannot declare more than 10000 local variables"
I expect that's a SQL Server limitation (albeit not listed in "Maximum Capacity Specifications for SQL Server"), if correct then all methods of running at a single script will have the same problem.
Better to break it up into smaller pieces—this should also make maintenance much easier.
You could create a .bat file that runs sqlcmd and exec your batch sql file. in c# you can then launch a cmd window as a process, sending the location of the .bat file as an argument.
精彩评论