Software Development Network>> SQL Server>> Executing .sql file using in .NET
Hello,
I want to execute .sql files against my database in c#.
please Help me.
Hello, Jens
Yes i know that you have posted that .
but i have replied it problem of that code
bcoz i had written same kind of code.
http://forums.microsoft.com/MSDN/showpost.aspx postid=323013&siteid=1
Uday
I assume this is the problem you are referring to:
"Code gives error where GO command is there in script;".
A SqlCommand string cannot contain the "GO" command. If you remove the lines containing the "GO" commands you should be fine.
Or you can split the file .sql file into multiple files at the lines where the "GO" commands were originally.
Thanks peter for reply
I have already tried script removeing "GO" but still it is not working.
actually i have generated script files by system(SQL Sever Enterprise Manager) itself.
Jens Thanks for Reply
I have .sql file generated by SQL Server Enterprise manager.
i want to execute this file. but it does not.
Then i have generate .sql file for each object separately.
now file table.sql (for tables only) runs correctly,
but for view (view.sql) doesnot run properly.
in all case error is same
"Create view must be first line in Query Batch."
Now what to do
Waiting for Your Reply
Emersion
Ok, did you try to serparate the string object you are getting back from reading from the file by splitting it into a string array and executing each string in the string array Thats the think which comes up in mind for this problem.Jens.
Executing .sql file using in .NET
Avocado
Hello, Jens
Yes i know that you have posted that .
but i have replied it problem of that code
bcoz i had written same kind of code.
http://forums.microsoft.com/MSDN/showpost.aspx postid=323013&siteid=1
Uday
Smart Akhtar
I assume this is the problem you are referring to:
"Code gives error where GO command is there in script;".
A SqlCommand string cannot contain the "GO" command. If you remove the lines containing the "GO" commands you should be fine.
adrianf
Or you can split the file .sql file into multiple files at the lines where the "GO" commands were originally.
Sung M Kim
Thanks peter for reply
I have already tried script removeing "GO" but still it is not working.
actually i have generated script files by system(SQL Sever Enterprise Manager) itself.
Warren Read - MSFT
HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---
R2ks
Jens Thanks for Reply
I have .sql file generated by SQL Server Enterprise manager.
i want to execute this file. but it does not.
Then i have generate .sql file for each object separately.
now file table.sql (for tables only) runs correctly,
but for view (view.sql) doesnot run properly.
in all case error is same
"Create view must be first line in Query Batch."
Now what to do
Waiting for Your Reply
Emersion
OptikConnex
Ok, did you try to serparate the string object you are getting back from reading from the file by splitting it into a string array and executing each string in the string array
Thats the think which comes up in mind for this problem.
Jens.
e6matt
funny thing, I posted that this week in the SMO group:
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=318250&SiteID=1
HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---