How do I use OUTPUT TO in Sybase using C#

655 Views Asked by At

I want to extract some tables from Sybase db using c# and currently I tried in sybase command and it works fine. but how Should I do this in c#?

SELECT * FROM users;
OUTPUT TO 'C:\\temp\\sample.sql' 
FORMAT TEXT

in C# I do like this.

 SAConnection myConnection = new SAConnection(connectionString);
 {
      myConnection.Open();
      SACommand myCommand = myConnection.CreateCommand();
      myCommand.CommandText = @"select * from users  OUTPUT TO " + "'C:\temp\sample.sql'" + " FORMAT TEXT ";
      SADataReader myDataReader = myCommand.ExecuteReader();                   
      myDataReader.Close();
      myConnection.Close();

 } 

But I receive an error "Syntax Error near 'OUTPUT' at line 1.

1

There are 1 best solutions below

1
On BEST ANSWER

you can try to use UNLOAD statement TO [filepath]

myCommand.CommandText = @"UNLOAD SELECT * FROM users TO " + "'C:\temp\sample.sql'";

Note: the filepath must be in the sybase server file system and not in your application side.

e.g.

web server(your app) and database server(server where sybase in installed)

if you set your filepath to C:\sample.sql, you get the file in your database server C:\ directory and not in web server.

you can refer to this previous answer and this document

OUTPUT TO is a dbisql command, not a SQL statement recognized by the database server.
-Graeme Perrow