Redian新闻
>
Oracle XE DBconnection from ASPX (转载)
avatar
Oracle XE DBconnection from ASPX (转载)# DotNet - 窗口里的风景
i*p
1
【 以下文字转载自 Database 讨论区 】
发信人: isup (No), 信区: Database
标 题: Oracle XE DBconnection from APSX
发信站: BBS 未名空间站 (Mon May 21 19:03:54 2007)
Could anyone show me the piece of code for ASPX (C# and/or VB) to access
Oracle XE?
Thanks.
avatar
y*o
2
This is what I did.
// In web.config:

providerName="System.Data.OracleClient" />
providerName="System.Data.SqlClient" />

...
// End
// In aspx file:

【在 i**p 的大作中提到】
: 【 以下文字转载自 Database 讨论区 】
: 发信人: isup (No), 信区: Database
: 标 题: Oracle XE DBconnection from APSX
: 发信站: BBS 未名空间站 (Mon May 21 19:03:54 2007)
: Could anyone show me the piece of code for ASPX (C# and/or VB) to access
: Oracle XE?
: Thanks.

avatar
i*p
4
Can I use ODP.net with .NET framework and Web Matrix? What do I need to
download?
Oracle website says to use it with Visual Studio .NET.

【在 b****u 的大作中提到】
: you can find examples of different connection strings here.
: http://www.connectionstrings.com/

avatar
b*u
5
not familiar with oracle, is ODP.net a .net library provided by oracle?
avatar
i*p
6
I think so.

【在 b****u 的大作中提到】
: not familiar with oracle, is ODP.net a .net library provided by oracle?
avatar
i*p
7
Thank you!
But I don't think you have accessed DB in your ASPX part of code. Cuuld you
show me your code to run "select" command?
Is that something like SqlDataSource1.Select()?

local
True"
MyCompute

【在 y********o 的大作中提到】
: This is what I did.
: // In web.config:
:
: : providerName="System.Data.OracleClient" />
: : providerName="System.Data.SqlClient" />
:

avatar
y*o
8
Why? I have SelectCommand="select blah blah " in the ASPX file. Please che
ck my original reply and verify.

you

【在 i**p 的大作中提到】
: Thank you!
: But I don't think you have accessed DB in your ASPX part of code. Cuuld you
: show me your code to run "select" command?
: Is that something like SqlDataSource1.Select()?
:
: local
: True"
: MyCompute

avatar
i*p
9
I may not understand how your code work. I am used to run conn.open and the
like. But it seems it is not necessary to run it in your method. Is your
method named ODP.NET?

che

【在 y********o 的大作中提到】
: Why? I have SelectCommand="select blah blah " in the ASPX file. Please che
: ck my original reply and verify.
:
: you

avatar
y*o
10
So, you wanna open the connection in your code-behind?
For oracle, do this:
Instantiate an OracleDataSource object and pass your db user name and passow
rd as well as the network protocol to its setter methods, like so:
OracleDataSource ods = new OracleDataSource();
ods.setUser(dbUser); // e.g. "hr"
ods.setPassword(dbPassword); // e.g. "hr"
ods.setDriverType(driverType); // e.g. "oci8"
ods.setNetworkProtocol(networkProtocol); // e.g. "ipc"
And then you say,
Connection conn = ods.getConnection(

【在 i**p 的大作中提到】
: I may not understand how your code work. I am used to run conn.open and the
: like. But it seems it is not necessary to run it in your method. Is your
: method named ODP.NET?
:
: che

avatar
i*p
11
Compiler Error Message: CS0246: The type or namespace name 'OracleDataSource
' could not be found (are you missing a using directive or an assembly
reference?)
How can I include the name space in c#?

passow

【在 y********o 的大作中提到】
: So, you wanna open the connection in your code-behind?
: For oracle, do this:
: Instantiate an OracleDataSource object and pass your db user name and passow
: rd as well as the network protocol to its setter methods, like so:
: OracleDataSource ods = new OracleDataSource();
: ods.setUser(dbUser); // e.g. "hr"
: ods.setPassword(dbPassword); // e.g. "hr"
: ods.setDriverType(driverType); // e.g. "oci8"
: ods.setNetworkProtocol(networkProtocol); // e.g. "ipc"
: And then you say,

avatar
y*o
12
O, sorry, that code is for oracle jdbc.
I can connect to my Oracle 10g using ODBC, not sure if this is what you wann
a use.
oracleConn = new OdbcConnection();
oracleConn.ConnectionString = @"DSN=OraServiceName; UID=myusername;PWD=my
passwd; DRIVER= {Microsoft ODBC for Oracle}; SERVER=110.119.114.120;";
oracleConn.Open();
I hope this would help.

OracleDataSource

【在 i**p 的大作中提到】
: Compiler Error Message: CS0246: The type or namespace name 'OracleDataSource
: ' could not be found (are you missing a using directive or an assembly
: reference?)
: How can I include the name space in c#?
:
: passow

avatar
i*p
13
Thanks! I like this method.
I am confused by OraServiceName. I installed Oracle 10g XE with all default
settings in my computer(Name: blue, IP:168.192.0.5). What is the
OraServiceName?
Aslo, Do I need convert {Microsoft ODBC for Oracle} to some string or value
or just it? I am wondering how Microsoft ASP.NET can regnize {Microsoft
ODBC for Oracle} if we don't convert it to some driver file name.

wann
my

【在 y********o 的大作中提到】
: O, sorry, that code is for oracle jdbc.
: I can connect to my Oracle 10g using ODBC, not sure if this is what you wann
: a use.
: oracleConn = new OdbcConnection();
: oracleConn.ConnectionString = @"DSN=OraServiceName; UID=myusername;PWD=my
: passwd; DRIVER= {Microsoft ODBC for Oracle}; SERVER=110.119.114.120;";
: oracleConn.Open();
: I hope this would help.
:
: OracleDataSource

avatar
y*o
14
Do you know how to create a DSN?
The code I showed you uses a DSN connection. The name can be anything you c
hoose. Once you have the DSN set up, the connection will be OK.

default
value

【在 i**p 的大作中提到】
: Thanks! I like this method.
: I am confused by OraServiceName. I installed Oracle 10g XE with all default
: settings in my computer(Name: blue, IP:168.192.0.5). What is the
: OraServiceName?
: Aslo, Do I need convert {Microsoft ODBC for Oracle} to some string or value
: or just it? I am wondering how Microsoft ASP.NET can regnize {Microsoft
: ODBC for Oracle} if we don't convert it to some driver file name.
:
: wann
: my

avatar
i*p
15
I tried to create system and user DSN with both "Oracle in XE" and "
Microsoft ODBC for Oracle" driver, but all of them got an error when the
code reached to oracleConn.Open().
There is a testing procedure when I set system DSN with driver "Oracle in XE
" and connection test is successful.
Could you show me how you set your DSN in your method?
Here is my error meesage from oracleConn.Open().
ERROR [NA000] [Microsoft][ODBC driver for Oracle][Oracle]Error while trying
to retrieve text for error OR

【在 y********o 的大作中提到】
: Do you know how to create a DSN?
: The code I showed you uses a DSN connection. The name can be anything you c
: hoose. Once you have the DSN set up, the connection will be OK.
:
: default
: value

avatar
i*p
16
Finally, I got it work by following connection string:
oracleConn.ConnectionString = "Driver={Oracle in XE};Server=XE;Uid=user/
passwd;";
I still wonder why my DSN setting does not work. DSN OracleXE is set to the
same as above. It passes connection test succesfully. But .Open() fails when
I use the following connect strings:
oracleConn.ConnectionString = "DSN=OracleXE;";
oracleConn.ConnectionString = @"DSN=OracleXE;";
Any reasons?

c

【在 y********o 的大作中提到】
: Do you know how to create a DSN?
: The code I showed you uses a DSN connection. The name can be anything you c
: hoose. Once you have the DSN set up, the connection will be OK.
:
: default
: value

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。