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.
you can try to use
UNLOAD
statementTO
[filepath]
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 serverC:\
directory and not in web server.you can refer to this previous answer and this document