Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sudhapec
Starting Member
4 Posts |
Posted - 2004-04-21 : 09:26:34
|
| FriendsI want to run sql script for creating of database whichcontains tables and stored procedures by setup and deployment projectin VS.NET. I have created customaction and passing the stringcontaining script to the ExecuteNonQuery() procedure to run the scriptThe problem is where ever GO statement is there in the script itis giving problem. I read somewhere that " Your script must not include any go statements. These are used only by Query Analyzer or the osql.exe utility. If they are present in your script when using it with ADO.NET (as in this demo), then the ExecuteNonQuery will fail."If i remove Go from the script then it is giving exception againtelling that "Incorrect syntax near the keyword Procedure"where ever create Procedure statement is therePlease help me in this regard. |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-04-21 : 19:47:31
|
When you run a script inside Query Analyzer, it uses GO to split a script up into smaller batches.You can do the same thing in your VB.NET code. Read the script file, then break it up using GO and run each part separately.Here is a bit of C# code that will return an array of batches, I'm sure you know how to convert it to VB.NET.private string[] ParseSqlString(string sql){ string[] batches; string pattern = @"\nGO\s*"; batches = Regex.Split(sql, pattern); return batches;}Damian |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2004-04-21 : 19:55:02
|
| You can use osql which execute files and process the "GO" keyword.. the Process class in the Diagnostic namespace makes this a trivial exercise....DavidM"If you are not my family or friend, then I will discriminate against you" |
 |
|
|
sudhapec
Starting Member
4 Posts |
Posted - 2004-04-22 : 03:37:45
|
| Sir,If i use OSQL.exe how can i know the path where OSQL.exe is therealso the path may vary from machine to machine based on where the sqlserver is insallledor it must be there in the path environment variable of DOS ( which may not be case always)Please reply to this query |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-04-22 : 03:45:57
|
OSQL is in the path on a standard install. Or you can do it my way Damian |
 |
|
|
sudhapec
Starting Member
4 Posts |
Posted - 2004-04-23 : 04:32:46
|
| Thank you very much Byrmol and MerkinI have used OSQL for creating the databaseand it is working fineWishing you all the bestKeep in touchsudhakar.kasina@tcs.comTata Consultancy Services, mumbai |
 |
|
|
sudhapec
Starting Member
4 Posts |
Posted - 2004-04-30 : 05:35:52
|
| we can invoke OSQL command from your vb.net codeyou need not mention the path for osql.exe for this.// file containing your scriptstring strFilepath = "c:\myfolder\myscript.sql";// append double codes to string at both endsstring strFilepathWithQuotes = "\"" + strFilepath + "\"";// form argument string for osqlstring strOsqlArg = string.Format("-S {0} -U {1} -P {2} -i {3} ,strDBSource,strDBUser,strDBPassword,strFilepathWithQuotes );ProcessStartInfo psi =new ProcessStartInfo("osql.exe ",strOsqlArg);Process p = Process.Start( psi );p.WaitForExit(); |
 |
|
|
|
|
|
|
|