首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

使用.NET连接到AS400

使用.NET连接到AS400,您可以使用以下方法:

  1. 使用IBM.Data.DB2.iSeries组件

IBM.Data.DB2.iSeries是一个专门为AS/400系统设计的.NET数据提供程序。您可以使用NuGet包管理器将其添加到您的项目中。

安装IBM.Data.DB2.iSeries:

代码语言:txt
复制
Install-Package IBM.Data.DB2.iSeries

示例代码:

代码语言:csharp
复制
using IBM.Data.DB2.iSeries;
using System.Data.Common;

string connectionString = "DataSource=AS400_IP_ADDRESS;UserID=USERNAME;Password=PASSWORD;DefaultCollection=LIBRARY_NAME;";

using (iDB2Connection connection = new iDB2Connection(connectionString))
{
    connection.Open();

    string sql = "SELECT * FROM TABLE_NAME";

    using (iDB2Command command = new iDB2Command(sql, connection))
    {
        using (DbDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                // 读取数据
            }
        }
    }
}
  1. 使用ODBC驱动程序

您可以使用ODBC驱动程序连接到AS/400系统,并使用ADO.NET的OdbcConnection对象进行数据库操作。

安装ODBC驱动程序:

代码语言:txt
复制
Install-Package System.Data.Odbc

示例代码:

代码语言:csharp
复制
using System.Data.Odbc;

string connectionString = "Driver={iSeries Access ODBC Driver};System=AS400_IP_ADDRESS;Uid=USERNAME;Pwd=PASSWORD;DefaultLibraries=LIBRARY_NAME;";

using (OdbcConnection connection = new OdbcConnection(connectionString))
{
    connection.Open();

    string sql = "SELECT * FROM TABLE_NAME";

    using (OdbcCommand command = new OdbcCommand(sql, connection))
    {
        using (OdbcDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                // 读取数据
            }
        }
    }
}
  1. 使用OLE DB驱动程序

您还可以使用OLE DB驱动程序连接到AS/400系统,并使用ADO.NET的OleDbConnection对象进行数据库操作。

安装OLE DB驱动程序:

代码语言:txt
复制
Install-Package System.Data.OleDb

示例代码:

代码语言:csharp
复制
using System.Data.OleDb;

string connectionString = "Provider=IBMDA400;Data Source=AS400_IP_ADDRESS;User ID=USERNAME;Password=PASSWORD;Default Collection=LIBRARY_NAME;";

using (OleDbConnection connection = new OleDbConnection(connectionString))
{
    connection.Open();

    string sql = "SELECT * FROM TABLE_NAME";

    using (OleDbCommand command = new OleDbCommand(sql, connection))
    {
        using (OleDbDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                // 读取数据
            }
        }
    }
}

以上是三种连接AS/400系统的方法,您可以根据需要选择合适的方法。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

【转载】数据库链接字符串大集合

SQL Server 2005 SQL Native Client ODBC Driver 标准安全连接 Driver={SQL Native Client};Server=myServerAddress; Database=myDataBase;Uid=myUsername;Pwd=myPassword; 受信的连接 Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes; "Integrated Security=SSPI" 与 "Trusted_Connection=yes" 是相同的。 连接到一个SQL Server实例 指定服务器实例的表达式和其他SQL Server的连接字符串相同。 Driver={SQL Native Client};Server=myServerName/theInstanceName;Database=myDataBase; Trusted_Connection=yes; 指定用户名和密码 oConn.Properties("Prompt") = adPromptAlways Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase; 使用MARS (multiple active result sets) Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;MARS_Connection=yes; "MultipleActiveResultSets=true"与MARS_Connection=yes"是相同的。 使用ADO.NET 2.0作为MARS的模块。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。 验证网络数据 Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;Encrypt=yes; 使用附加本地数据库文件的方式连接到本地SQL Server Express实例 Driver={SQL Native Client};Server=./SQLExpress; AttachDbFilename=c:/asd/qwe/mydbfile.mdf; Database=dbname;Trusted_Connection=Yes; 为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。 使用附加本地数据文件夹中的数据库文件的方式连接到本地SQL Server Express实例 Driver={SQL Native Client};Server=./SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes; 为何要使用Database参数?如果同名的数据库已经被附加,那么SQL Server将不会重新附加。 数据库镜像 Data Source=myServerAddress; Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True; SQL Native Client OLE DB Provider 标准连接 Provider=SQLNCLI;Server=myServerAddress; Database=myDataBase;Uid=myUsername;Pwd=myPassword; 受信的连接 Provider=SQLNCLI;Server=myServerAddress; Database=myDataBase;Trusted_Connection=yes; 连接到SQL Server实例 指定服务器实例的表达式和其他SQL Server的连接字符串相同。 Provider=SQLNCLI;Server=myServerName/theInstanceName; Database=myDataBase;Trusted_Connection=yes; 使用帐号和密码 oConn.Properties("Prompt") = adPromptAlways oConn.Open "Provider=SQLNCLI;Server=myServerAd

05

初学ASP.NET

今天头一次接触了ASP.NET的技术,感觉确实存在着一些开发便捷之处,一些开发便捷之处,下面就简要谈谈我所学的一些体会,虽然可能很浅显,但依旧是我所亲身经历的。。。 1、读取数据库操作       在适当位置拖放一个DataList控件,新建数据源,在设置之后,可以选择用指定sql或存储过程,或是指定自表或视图的列,来确定数据源,例如:select top 10 id, news_title, news_time  from news_info order by id desc 按降序排列从以上表中三个字段中读取的前10条数据,完成配置工作。 2、根据所选项来跳转到相应页面   1) Imports System       Imports System.Data       Imports System.Data.SqlClient       ------引入    Dim connection As SqlConnection 2) connection = New                 SqlConnection(ConfigurationManager.ConnectionStrings              ("WebConnectionString3").ConnectionString)         connection.Open()        -------数据库连接语句,打开数据库,可以将此写成一个类DB(类中Function需写返回值),放在App_Code内,之后便可进行调用,   Dim connection As SqlConnection = DB.creatconnection        connection.Open()直接对DB类进行调用即可。 3) 实例化command对象,        command = New SqlCommand("Select * From News_Info Where Id='" & Temp & "'", connection)         Sqlrs = command.ExecuteReader         Sqlrs.Read()              其中command是SqlCommand类,Temp是接受Id值的局部变量,执行其中的sql语句。 4) Label1.Text = Sqlrs.Item("News_Title")       ------将取到的值放入Label控件中,用以显示。         总而言之,就是执行连接数据库-打开数据库-执行命令-关闭数据库这几步操作。 3、细微环节       变量的表示:' " & & " '       查询分析器与.NET中不区分大小写       Response.Write("<" + "/script>")等同于Response.Write("</script>")       '单引号必须过滤!       若是修改更新单条语句,要加where,否则数据全部会改变

03
领券