J'importe Sybase.Data.AseClient.dll
dans mon projet C# pour me connecter à une base de données sybase et faire une requête comme ceci
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 ;
}
Bizarrement, j'ai obtenu une exception comme celle-ci
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:
Il montre que le conflit entre le personnage client et le personnage serveur, mais je ne sais pas comment résoudre ce problème, quelqu'un peut m'aider ?
Merci Parado, j'ai suivi vos conseils et j'ai obtenu ceci
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