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.s ql" and "setup.bat" with the following
code:
AttachAtpDBFile = File.CreateText (@"c:\attachDB. sql");
AttachAtpDBFile .AutoFlush = true;
AttachAtpDBFile .WriteLine("CRE ATE 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("@ech o off");
SetupBatchFile. WriteLine("scm. exe -Action 1 -Silent 1 -Service MSSQLServer");
SetupBatchFile. WriteLine(@"osq l -E -i {0} > c:\log.txt", @"c:\attachDB.s ql");
SetupBatchFile. WriteLine("@ech o on");
SetupBatchFile. Close();
I execute the Batch-File with the following code:
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents=false ;
proc.StartInfo. FileName= @"c:\setup.bat" ;
proc.StartInfo. Arguments="";
proc.Start();
proc.WaitForExi t();
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.s ql" and "setup.bat" with the following
code:
AttachAtpDBFile = File.CreateText (@"c:\attachDB. sql");
AttachAtpDBFile .AutoFlush = true;
AttachAtpDBFile .WriteLine("CRE ATE 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("@ech o off");
SetupBatchFile. WriteLine("scm. exe -Action 1 -Silent 1 -Service MSSQLServer");
SetupBatchFile. WriteLine(@"osq l -E -i {0} > c:\log.txt", @"c:\attachDB.s ql");
SetupBatchFile. WriteLine("@ech o on");
SetupBatchFile. Close();
I execute the Batch-File with the following code:
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents=false ;
proc.StartInfo. FileName= @"c:\setup.bat" ;
proc.StartInfo. Arguments="";
proc.Start();
proc.WaitForExi t();
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.
Comment