G
Guest
Hello all,
I would like to generate a Sql-Script-File and a Batch-File to execute the
Batch-File over C#-Code and use the SQL-File as an Input-File for the command
"osql" in the Batch-File.
I generate the two files "attachDB.sql" and "setup.bat" with the following
code:
AttachAtpDBFile = File.CreateText(@"c:\attachDB.sql");
AttachAtpDBFile.AutoFlush = true;
AttachAtpDBFile.WriteLine("CREATE DATABASE {0}", DatabaseName);
AttachAtpDBFile.WriteLine("ON PRIMARY (FILENAME = '{0}')", AtpMdfFilePath);
AttachAtpDBFile.WriteLine("FOR ATTACH");
AttachAtpDBFile.WriteLine("go");
AttachAtpDBFile.WriteLine("USE ATP");
AttachAtpDBFile.WriteLine("go");
AttachAtpDBFile.Close();
SetupBatchFile = File.CreateText(@"c:\setup.bat");
SetupBatchFile.AutoFlush = true;
SetupBatchFile.WriteLine("@echo off");
SetupBatchFile.WriteLine("scm.exe -Action 1 -Silent 1 -Service MSSQLServer");
SetupBatchFile.WriteLine(@"osql -E -i {0} > c:\log.txt", @"c:\attachDB.sql");
SetupBatchFile.WriteLine("@echo on");
SetupBatchFile.Close();
I execute the Batch-File with the following code:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName= @"c:\setup.bat";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
The problem is that when I'm executing the Batch-File the command "osql"
returns following error message:
The Inputfile attachDB.sql can not be opened. File or directory is not
available.
But when I'm executing the Batchfile over a shell or an explorer the script
creates the database successfully (in this case the file attachDB.sql is
available)!
Does someone know what I'm doing wrong, or what I have to consider?
With kind regards
David R.
I would like to generate a Sql-Script-File and a Batch-File to execute the
Batch-File over C#-Code and use the SQL-File as an Input-File for the command
"osql" in the Batch-File.
I generate the two files "attachDB.sql" and "setup.bat" with the following
code:
AttachAtpDBFile = File.CreateText(@"c:\attachDB.sql");
AttachAtpDBFile.AutoFlush = true;
AttachAtpDBFile.WriteLine("CREATE DATABASE {0}", DatabaseName);
AttachAtpDBFile.WriteLine("ON PRIMARY (FILENAME = '{0}')", AtpMdfFilePath);
AttachAtpDBFile.WriteLine("FOR ATTACH");
AttachAtpDBFile.WriteLine("go");
AttachAtpDBFile.WriteLine("USE ATP");
AttachAtpDBFile.WriteLine("go");
AttachAtpDBFile.Close();
SetupBatchFile = File.CreateText(@"c:\setup.bat");
SetupBatchFile.AutoFlush = true;
SetupBatchFile.WriteLine("@echo off");
SetupBatchFile.WriteLine("scm.exe -Action 1 -Silent 1 -Service MSSQLServer");
SetupBatchFile.WriteLine(@"osql -E -i {0} > c:\log.txt", @"c:\attachDB.sql");
SetupBatchFile.WriteLine("@echo on");
SetupBatchFile.Close();
I execute the Batch-File with the following code:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName= @"c:\setup.bat";
proc.StartInfo.Arguments="";
proc.Start();
proc.WaitForExit();
The problem is that when I'm executing the Batch-File the command "osql"
returns following error message:
The Inputfile attachDB.sql can not be opened. File or directory is not
available.
But when I'm executing the Batchfile over a shell or an explorer the script
creates the database successfully (in this case the file attachDB.sql is
available)!
Does someone know what I'm doing wrong, or what I have to consider?
With kind regards
David R.