2
votes

I import Sybase.Data.AseClient.dll into my C# project for connecting to a sybase database and query something like this

private DataSet query(string jjoprid)
{
    string queryStr = "select oprid, oprname,orgid,lastmodified from                SA_CXTC_OPRINFO where oprid = \"" + jjoprid + "\";";
    DataSet ds ;
    try
    {
        conn = new AseConnection("Data Source=192.168.100.251;database=thq;" +
            "charset=cp936;Port=7000;UID=snhqdbo;PWD=janhq@ary");
        command = new AseCommand(queryStr, conn);
        adapter = new AseDataAdapter(command);
        ds = new DataSet();
        adapter.Fill(ds);                
    }
    catch (AseException ex)
    {
        Console.WriteLine(ex.Message);
        return null;
    }
    finally
    {
        if (null != conn)
            conn.Close();
    }    
    return ds ;
}

Strangely, I got a Exception like this

catch Sybase.Data.AseClient.AseException
  Message=Character set conversion is not available between client character set 'cp936' and server character set 'iso_1'.

  Source=Sybase.Data.AseClient
  StackTrace:
       at Sybase.Data.AseClient.AseConnectionImpl.CheckResult(Int32 res, Boolean forOpen)
       at Sybase.Data.AseClient.AseConnectionImpl.Open()
       at Sybase.Data.AseClient.AseConnectionPool.GetConnection(AseConnection conn)
       at Sybase.Data.AseClient.AseConnectionPoolManager.GetConnection(String connectionString, AseConnection conn)
       at Sybase.Data.AseClient.AseConnection.Open()
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
       at CXTC运维.Form1.query(String jjoprid) location d:\Documents and Settings\11075452\My Documents\Visual Studio 2010\Projects\CXTC运维\CXTC运维\Form1.cs:行号 41
  InnerException: 

It shows that the conflict between client character and server character, but I don't how to solve this problem, anyone can help me ?

Thank you Parado, I followed your advice and got this


catch Sybase.Data.AseClient.AseException
  Message=Attempt to locate entry in sysdatabases for database 'thq' by name failed - no entry found under that name. Make sure that name is entered properly.

  Source=Sybase.Data.AseClient
  StackTrace:
       at Sybase.Data.AseClient.AseConnectionImpl.CheckResult(Int32 res, Boolean forOpen)
       at Sybase.Data.AseClient.AseConnectionImpl.Open()
       at Sybase.Data.AseClient.AseConnectionPool.GetConnection(AseConnection conn)
       at Sybase.Data.AseClient.AseConnectionPoolManager.GetConnection(String connectionString, AseConnection conn)
       at Sybase.Data.AseClient.AseConnection.Open()
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
       at CXTC运维.Form
1

1 Answers

2
votes

Try to change characterset to iso_1 as below

conn = new AseConnection("Data Source=192.168.100.251;database=thq;" +
                    "charset=iso_1;Port=7000;UID=snhqdbo;PWD=janhq@ary");