How to execute sql script file in asp.net c#

2
Our Reader Score
[Total: 0 Average: 0]

EXECUTE SQL SCRIPT FROM C#

To create SQL Database using Asp.net is quite difficult, Here I this article am writing how to create SQL Database and how to Run the SQL Script File in asp.net. These two DLL you have to import to perform these tasks.

  • Microsoft.SqlServer.ConnectionInfo.dll 
  • Microsoft.SqlServer.Smo.dll.

 

So that it iterates SQL scripts in a directory and executes them with ConnectionContext.ExecuteNonQuery.
Code :

Note:

  • Microsoft.SqlServer.Smo.dll,Microsoft.SqlServer.ConnectionInfo.dll is need
  • You will find these online or check in ur windows ie In c/programfiles/sqlserver/assembly/…
  • Your database script contains “GO” if not using smo.dll it will throw error.


Thanks for reading


Get your Printable Copy

2 COMMENTS

  1. Hello,

    This is really interesting take on the concept. I never thought of it that way. I came across this site recently which I think it will be a great use of new ideas and informations. Thanks a lot…

LEAVE A REPLY