我想知道在.net Framework4.0中是否有从.Net连接到DB2数据库的功能
编辑:-我想知道是否有DB2提供商
发布于 2018-06-18 19:37:27
我还在搜索下载连接DB2的驱动程序。Here是DB2的所有客户端驱动程序及其版本的列表。
有关连接到DB2的信息,请访问here。以防将来链接可能会死掉,所以我在这里发布了示例代码。
using System;
using IBM.Data.DB2;
namespace dotNetSSLTest
{
class Program
{
static void Main(string[] args)
{
DB2Command MyDB2Command = null;
// Use the dsn alias that you defined in db2dsdriver.cfg with the db2cli writecfg command in step 1.
String MyDb2ConnectionString = "database=alias;uid=userid;pwd=password;";
DB2Connection MyDb2Connection = new DB2Connection(MyDb2ConnectionString);
MyDb2Connection.Open();
MyDB2Command = MyDb2Connection.CreateCommand();
MyDB2Command.CommandText = "SELECT branch_code, city from GOSALES.BRANCH";
Console.WriteLine(MyDB2Command.CommandText);
DB2DataReader MyDb2DataReader = null;
MyDb2DataReader = MyDB2Command.ExecuteReader();
Console.WriteLine("BRANCH\tCITY");
Console.WriteLine("============================");
while (MyDb2DataReader.Read())
{
for (int i = 0; i <= 1; i++)
{
try
{
if (MyDb2DataReader.IsDBNull(i))
{
Console.Write("NULL");
}
else
{
Console.Write(MyDb2DataReader.GetString(i));
}
}
catch (Exception e)
{
Console.Write(e.ToString());
}
Console.Write("\t");
}
Console.WriteLine("");
}
MyDb2DataReader.Close();
MyDB2Command.Dispose();
MyDb2Connection.Close();
}
}
}如果有人找不到试用版的DB2数据库服务器,那么here就是免费试用版列表。此外,开发人员社区版是免费的,可以无限制地使用。
https://stackoverflow.com/questions/979473
复制相似问题