CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2007

    Sending OSQL command to command prompt

    Hi all,

    I have two major problems about running OSQL from my c# code, first is running .sql commands using -i parameter with long and blank containing file locations and the second is passing the right command format to command prompt.

    1- When I type a command like
    osql -U test -P testpass -S PROJETEST -i C:\testsql.sql
    osql works fine.

    But when I change it to sth like

    osql -U test -P testpass -S PROJETEST -i C:\Users\ceyhun.ganioglu\Documents\Visual Studio 2008\Projects\TestProjectLoader\TestProjectLoader\bin\Debug\sqlscripts\2008_r2\testsql.sql
    I get an error like "osql does not support all features of SQL Server 2008 R2." Adding the " at the beginning and end of the file location did not work.

    2- I have the following code in my C# code. Does not matter if I get the directory dynamically or just type C:\\testsql.sql after -i parameter, I get the same error.
    string mevcut_adres = Directory.GetCurrentDirectory();
    Process.Start("cmd.exe", "/K osql -U " + kullanici_adi.Text + " -P " + kullanici_sifre.Text + " -S " + sql_server_list.Text + "-i " + mevcut_adres + "\\sqlscripts\\2008_r2\\test.sql");
    I could not make it work at all. Can anybody help?

    Many thanks

  2. #2
    Join Date
    Feb 2011
    United States

    Re: Sending OSQL command to command prompt

    testsql.sql files are identical in both C:\ and C:\Users...\2008_rs\, I assume?

    Could be a permissions issue, possibly?
    Best Regards,

    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)