1.首先 如果安装Synbase Client的话,会在安装目录中发现ADO.NET(\sybase\ADO.NET)连接Sybase数据库的相关事例以及需要用到的dll。
Sybase.Data.AseClient.dll sybdrvado11.dll sybdrvssl.dll (C:\sybase\ADO.NET\dll)
2.而后需要确定系统目录(C:\Windows\System32)中包含msvcr71.dll与sybdrvado11.dll。如果没有,需要先将这两个dll拷到系统目录中,重启机器。
msvcr71.dll可以从网上任意下载
3. 如下是代码,项目需要添加Sybase.Data.AseClient.dll:
private static string connStr = "Data Source=‘{0}‘;Port=‘{1}‘;UID=‘{2}‘;PWD=‘{3}‘;Database=‘{4}‘;"; private static string commStr = "sp_help {0}"; private static AseConnection conn; private static AseCommand cmd = null; private static AseDataReader reader = null;
public static void CreateConn() { conn = new AseConnection(string.Format(connStr, Host, Port, User, PWD, DB_NAME)); try { conn.Open(); } catch (AseException ex) { throw ex; } }
public static void CloseConn() { if (reader != null && !reader.IsClosed) reader.Close(); if (cmd != null) cmd.Dispose(); if (conn != null && conn.State != ConnectionState.Closed) conn.Close(); }
public static void ExecuteComm(string tableName) { CreateConn(); cmd = new AseCommand(string.Format(commStr, tableName), conn); AseDataAdapter adapter = new AseDataAdapter(cmd); DataSet ds = new DataSet(); try { adapter.Fill(ds); } catch { } dsDict.Add(tableName, ds); CloseConn(); }
4. 编译时,源代码编译时必须target在x86平台下。
5.相关技术可以参考sybase目录下的demo(\sybase\ADO.NET\Samples\CSharp\Simple):