Para este exemplo usaremos a conexão via ODBC driver.
Utilize o código a seguir em um projeto ASP.NET:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ODBCTest.aspx.cs" Inherits="ODBCTest" %>
<%@ Import Namespace="System.Data.Odbc" %>
<!DOCTYPE html>
<script runat="server" >
protected void Page_Load(object sender, EventArgs e)
{
OdbcConnection conn = null;
OdbcCommand command = null;
OdbcDataReader dr = null;
try
{
string connstr = "DRIVER={Tibero 5 ODBC Driver};SERVER=192.168.175.133;PORT=8629;DB=tibero;UID=sys;PWD=tibero;";
conn = new OdbcConnection(connstr);
conn.Open();
string sql = "SELECT USERNAME FROM DBA_USERS";
command = new OdbcCommand(sql, conn);
dr = command.ExecuteReader();
while (dr.Read())
{
Response.Write(dr[0].ToString());
Response.Write("<br/>");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
// Release allocated resources.
if (dr != null)
{
dr.Close();
dr = null;
}
command = null;
if (conn != null)
{
conn.Close();
conn = null;
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ODBC Test</title>
</head>
<body>
</body>
</html>
Nenhum comentário:
Postar um comentário