ASP.NET怎样连接oracle数据库?

ASP.NET怎样连接oracle数据库?,第1张

1.打开 安装目录D:\oracle\product\10.2.0\client_1\NETWORK\ADMIN文件夹下的tnsnames.ora文件,进行如下配置:

TOPTEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.122.10.9)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = toptest) ) )

在web.config文件中添加连接字符串,如:

<add name="OracleConn" connectionString="Data Source=TOPTESTUser ID=ds1Password=ds1Unicode=True" providerName="System.Data.OracleClient"/>

2.如果程序与数据库在同一台计算机上,则可以用这一连接。

<add name="OracleConn" connectionString="Data Source=10.100.1.9User ID=ds1Password=ds1Unicode=True" providerName="System.Data.OracleClient"/>

3.使用连接字符串访问数据库

public static readonly string connectionString = ConfigurationManager.ConnectionStrings["OracleConn"].ConnectionString

4.按照以上的步骤进行 *** 作,ASP.NET就能够成功地访问Oracle数据库

看了你的提问,我想说一下:

asp连接数据库oracle

1、利用ODBC,性能不是很稳定。

2、利用ADO,有两个驱动,一个是microsoft提供的,一个是oracle提供的。各有优缺点。

3、利用oracle专门给asp的驱动,性能最稳定,速度最快。我一直用这个。

<%

set Conn=server.CreateObject("adodb.connection")

'Conn.open "dsn=mmaximouid=userpwd=pwd"

Conn.open "maximo","user","pwd"

'dns="Driver={Microsoft ODBC for Oracle}UID=userPWD=pwdserver=10.128.64.7"

'Conn.open dns

'dns="Provider=MSDAORA.1Password=pwdUser ID=userData Source=thpmisPersist Security Info=True"

'dns="Provider=OraOLEDB.Oracle.1Password=pwdUser ID=userData Source=thpmisPersist Security Info=True"

'Conn.open dns

'set OraSession=Server.CreateObject("OracleInprocServer.XOraSession")

'set OraDatabase=OraSession.OpenDatabase("maximo","user/pwd",0)

'set ors=OraDatabase.CreateDynaset("select * from workorder",0)

'response.write "总共有" & ors.recordcount & "记录"

'on error resume next

'connstr="dsn=mmaximouid=userpwd=pwd"

'Conn.open connstr

%>

---------------------------------------------------------------

方法二:Dim objConn,myDSN

If Not IsObject(objConn) Then

Set objConn = Server.CreateObject("ADODB.Connection")

myDSN = "Provider=OraOLEDB.OracleData Source=Oracle_ShanghaiUser ID=scottPASSWORD=tigerPersist Security Info=True"

objConn.Open myDSN

End If

1、连入SQL*Plus

以system/manager用户登录,

SQL> conn system/manager

创建新的用户:如user1/pass1,赋予connect,resource权限。

SQL> grant connect,resource to user1 identified by pass1

SQL> conn user1/pass1

SQL> create table test(a date)

Oracle数据库的实例名,本例:oradb

Oracle用户名,本例:user1

Oracle主机字符串:oradb

tnsnames.ora文件中

ORADB =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.1.1)(PORT = 1521))

)

(CONNECT_DATA =

(SERVICE_NAME = oradb)

)

)

2、在IIS默认WWW目录下创建test.asp,用notebook编辑,输入以下代码

<%

set conn=server.createobject("adodb.connection")

dns="Provider=OraOLEDB.Oracle.1Persist Security Info=TrueUser ID=user1Password=pass1Data Source=oradb"

conn.Open dns

SQL="insert into test(a) values(sysdate)"

set rs=conn.execute(SQL)

set rs=nothing

conn.close

set conn=nothing

%>

<%

set conn=server.createobject("adodb.connection")

dns="Provider=OraOLEDB.Oracle.1Persist Security Info=TrueUser ID=user1Password=pass1Data Source=oradb"

conn.Open dns

SQL="select to_char(a,'hh24:mi:ss') from test"

set rs=conn.execute(SQL)

do while (not rs.eof)

%>

<table border=1>

<tr><td><%=rs.fields(0).value%></font></td>

</tr>

<%

rs.movenext

loop

rs.close

set rs=nothing

conn.close

set conn=nothing

%>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9893560.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存