Hi
I have an sqlscript file in which i have both the table creation,procedure creation function creating scripts.Am getting an error when am trying to execute the script file with the command for creating function included.All the tables are created.
Can you plz share ur idea.
Thanks in Advance
Loading
Mahesh ChandPosted Sep 16, 2008, 8:32 AM
Try this:
Add these namespaces to your application:
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
Add this code:
string sqlConnectionString = "Your connection string here";
FileInfo file = new FileInfo("Your .sql file or SQL string here ");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
If you don't see namespaces, add DLL reference to the project.
If your script is too large, you may want to parse it and break into chunks and execute them.