c# - Get osql output in command prompt -


i using following code execute osql command , output (like 2 rows affected etc) never finishes. please let me know missing.

string sqlfilepath = helper.getfilepath(sqlfilename, environment.currentdirectory);  process p = new process(); p.startinfo.filename = "cmd.exe"; p.startinfo.arguments = @"osql -e -s @server -d @database -t -n -i ""@sqlfile"""            .replace("@server", configurationmanager.appsettings["server"])            .replace("@database", path.getfilenamewithoutextension(db))            .replace("@sqlfile", sqlfilepath); p.startinfo.useshellexecute = false; p.startinfo.redirectstandardoutput = true; p.start();  string output = p.standardoutput.readtoend(); p.waitforexit(); 

i believe might running 2 separate problems:

  • set filename , arguments properties this:

    p.startinfo.filename = "osql.exe"; p.startinfo.arguments = @"-e -s @server -d @database -t -n -i ""@sqlfile"""     .replace("@server", configurationmanager.appsettings["server"])     .replace("@database", path.getfilenamewithoutextension(db))     .replace("@sqlfile", sqlfilepath); 
  • you might encounter encoding issue. make sure save .sql file using unicode encoding (codepage 1200) (here's question describes issue).


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -