Method 1: Use System. Data. oracleclient (you need to install the Oracle client and configure tnsnames. ora ).
Oracleconnectionstring: Data Source = orcl; user id = Scott; Password = tiger; persist Security info = false;
Method 2: Use oldedb to connect
Oracleconnectionstring:
Provider = oraoledb. oracle.1; user id = Scott; Password = tiger; Data Source = (description = (address_list = (address = (Protocol = TCP) (host = 10.10.125.250) (Port = 1521 ))) (CONNECT_DATA = (SERVICE_NAME = orcl )))
It seems that oledbcommandtype does not correspond to the ref cursor of Oracle on msdn, so it is discarded,
Method 3: The Oracle client is required, but tnsnames. ora is not required.
Connection string oracleconnectionstring
User ID = Scott; Password = tiger; Data Source = (description = (address_list = (address = (Protocol = TCP) (host = 10.10.125.250) (Port = 1521 ))) (CONNECT_DATA = (SERVICE_NAME = orcl )))
However, follow the Online Demo and often prompt:
An unprocessed "system. argumentexception" exception occurs in system. Data. oracleclient. dll.
Other information: Invalid Length for connection option 'data source', maximum length is 128.
Is the code wrong?
After calculation, what is the length of oracleconnectionstring over 180?
I gave some of the spaces and tried them one by one. The idea is enough.
If no exception exists, it won't be the length limit. I will add a space one by one. The result seems to be no more than 177 characters in length and can be connected? Is it true that Bt
String strconn = "User ID = Scott; Password = tiger; Data Source = (description = (address_list = (address = (Protocol = TCP) (host = 10.10.125.250) (Port = 1521) (CONNECT_DATA = (SERVICE_NAME = orcl )))";
MessageBox. Show (strconn. length. tostring ());
System. Data. oracleclient. oracleconnection oraconn = new system. Data. oracleclient. oracleconnection (strconn );
Try
{
Oraconn. open ();
MessageBox. Show (oraconn. state. tostring (); // 177
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
Finally
{
Oraconn. Close ();
}