Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running an sql script from VS2005 (C#)

Status
Not open for further replies.

Elroacho

Programmer
Apr 19, 2004
59
NZ
Hi,
I am trying to figure out a way of running an sql script into an sqlexpress server.

I have been looking at the sqlcmd tool, attemping to use this in a spawned process.

example...
Code:
            System.Diagnostics.Process proc = new System.Diagnostics.Process();

            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"sqlcmd .\sqlexpress -i ""C:\Program Files\PCIT\CDEvolution\CreateDB.sql"" -o ""C:\Program Files\PCIT\CDEvolution\CreateDBRes.txt""";

            Console.WriteLine(proc.StartInfo.FileName.ToString());

            try { proc.Start(); }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);            
            }

this returns an error that a file can't be found. I have checked and the required files are there. I have also taken the command string and manually run it through a cmd window and that works fine. But when I run it from code it won't work.

Any ideas on how to do this?

Cheers.
Kevin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top