i**p 发帖数: 902 | 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. |
y********o 发帖数: 2565 | 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.
|
b****u 发帖数: 1027 | 3 you can find examples of different connection strings here.
http://www.connectionstrings.com/ |
i**p 发帖数: 902 | 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/
|
b****u 发帖数: 1027 | 5 not familiar with oracle, is ODP.net a .net library provided by oracle? |
i**p 发帖数: 902 | 6 I think so.
【在 b****u 的大作中提到】 : not familiar with oracle, is ODP.net a .net library provided by oracle?
|
i**p 发帖数: 902 | 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" /> :
|
y********o 发帖数: 2565 | 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
|
|
i**p 发帖数: 902 | 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
|
y********o 发帖数: 2565 | 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
|
|
|
i**p 发帖数: 902 | 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,
|
y********o 发帖数: 2565 | 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
|
i**p 发帖数: 902 | 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
|
y********o 发帖数: 2565 | 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
|
i**p 发帖数: 902 | 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
|
i**p 发帖数: 902 | 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
|