我必须连接到安装在其他系统上的DB2数据库。我有服务器的机器名、要连接的数据库名、端口号和凭据。我的系统上没有安装任何用于DB2的客户端。我想使用OLEDB连接。
我可以在不安装客户端的情况下实现这一点吗?另外,请让我知道哪些参考dll可以帮助我实现这一点,即我应该使用什么- IBM Provider for DB2、Microsoft OLEDB provider for IBM或其他一些DB2?我在哪里能找到他们?
发布于 2013-01-01 18:37:34
有关OLEDB的信息,请参阅.NET DB2 OLEDB pre-requisites
另请参阅:what is the difference between OLE DB and ODBC data sources?
对于ODBC连接,我使用以下方法
连接字符串
<add name="DB2ConnectionString_XA"
connectionString="Driver={IBM DB2 ODBC DRIVER};Database=MyDB;Hostname=DB2GWXX;Protocol=TCPIP;Port=3700;Uid=ffghxa;Pwd=xxxx;"/>代码:
using (OdbcConnection odbcConnection = new OdbcConnection(db2ConnectionString))
{
odbcConnection.Open();
// string commandText = "";
using (OdbcCommand command = new OdbcCommand(commandText, odbcConnection))
{
command.CommandType = System.Data.CommandType.Text;
using (OdbcDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
}
}
}
}
}发布于 2016-06-08 19:20:56
我以前使用过ODBC,而不是OLEDB,但如果您决定改变您对ODBC的看法,我将不管怎样分享这个链接。您至少需要安装Db2客户端和驱动程序。这会将IMB“odbc驱动程序安装到您的系统(odbc数据源)中。这些驱动程序可从以下站点找到:http://www-01.ibm.com/support/docview.wss?uid=swg27016878。
安装后,添加对IBM.Data.DB2.dll的引用
https://stackoverflow.com/questions/13487357
复制相似问题