Help using C# application to connect to oracle database
I'm new to database.
I'm developing a C# GUI application in visual studio 2008 that is suppose to interact with oracle. After researching and trying out several sample codes, nothing works and I'm in desperate need of some help/advice/suggestions.
The simplest example I'm trying is to just get a button to run a simple SQL query. The code is:
private void button1_Click(object sender, EventArgs e)
string oradb = "Data Source=acme.gatech.edu;User Id=gtg880f;Password=******;";
OracleConnection conn = new OracleConnection(oradb); // C#
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select Location_Name from warehouse where Location_name = 'atlanta'";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
label1.Text = dr.GetString(0);
conn.Dispose();
I've installed many many version of oracle database and have included the Oracle.Data.Access under reference.
If I use putty and connect to acme.gatech.edu via port 22, I can type sqlplus / and run the query "elect Location_Name from warehouse where Location_name = 'atlanta'" and it'll work.
After some research, some say that if I can connect via sqlplus that means i can connect to the database but what do i need to implement to enable my c# code in visual studio to be able to do that.
I did a search on the forum but found nothing that matches this. In essence, I'm not sure what/how to specify such that I can connect to the acme.gatech.edu server and run sql commands.
Thanks,
Oky Sabeni
There're two ways you can get data in and out of database using .NET
#1 System.Data.OracleClient namespace - it's .NET avail out of the box
#2 Oracle.DataAccess.Client - aka "ODP.NET"
Download: http://www.oracle.com/technology/software/tech/windows/odpnet/index.html
Or download Beta because as of today it's the only version which supports .NET "TransactionScope" (I just tested seems like still it is NOT working Re: 10g Express + ODP.NET (version 2.111.6.20) > support TransactionScope? http://www.oracle.com/technology/software/tech/windows/odpnet/index1110710beta.html
QuickStart: http://www.installationwiki.org/ODP.NET_Getting_Started_Guide
Also there's a doc under Start menu>Programs>Oracle - OraOdac11g_BETA_home>Application Development>"Oracle Data Provider for .NET Developer's Guide"
It's worth reading just scroll down quick for code fragment.
Anyway here's two small examples:
Example 1: System.Data.OracleClient (Using library from M$)
* First you'll need to add reference to "System.Data.OracleClient".
IDbFactory oDbFactory = DbProviderFactories.GetFactory("System.Data.OracleClient");
IDbConnection oConn = oDbFactory.CreateConnection();
oConn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;";
// Or ...
oConn = new System.Data.OracleClient.OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;");
Example 2: ODP.NET from Oracle
IDbFactory oDbFactory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
IDbConnection oConn = oDbFactory.CreateConnection();
oConn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;";
// Or ...
oConn = new Oracle.DataAccess.Client.OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;");
string strSQL = "... SQL statement...";
int nPersonId = 0;
string strFirstName = null;
Person oPerson = null;
string strSQL = "SELECT Id FROM PERSON";
oCmd = oConn.CreateCommand();
oCmd.CommandText = strSQL;
oCmd.CommandType = System.Data.CommandType.Text;
IDataReader oRdr = oCmd.ExecuteReader();
while (oRdr.Read())
if (!Convert.IsDBNull(oRdr["Id"]))
nPersonId = (int) oRdr["Id"];
if (!Convert.IsDBNull(oRdr["FirstName"]))
strFirstName = (string)oRdr["FirstName"];
oPerson.Id = nPersonId;
oPerson.FirstName = strFirstName;
Example CREATE TABLE:
DECLARE
count_item int;
BEGIN
SELECT count(1) into count_item FROM user_sequences WHERE sequence_name = 'AUDITLOGSEQUENCE';
IF count_item > 0 THEN
begin
dbms_output.put_line('drop sequence AUDITLOGSEQUENCE');
EXECUTE IMMEDIATE ('DROP SEQUENCE AUDITLOGSEQUENCE');
end;
ELSE
dbms_output.put_line('no need to drop AUDITLOGSEQUENCE');
END IF;
EXECUTE IMMEDIATE 'CREATE SEQUENCE AUDITLOGSEQUENCE
MINVALUE 1
MAXVALUE 999999999999999999999999999
START WITH 1
INCREMENT BY 1
CACHE 20';
dbms_output.put_line('AUDITLOGSEQUENCE created');
SELECT count(1) into count_item FROM user_tables WHERE table_name = 'LOG';
IF count_item > 0 THEN
begin
dbms_output.put_line('drop table LOG');
EXECUTE IMMEDIATE ('DROP TABLE LOG');
end;
ELSE
dbms_output.put_line('no need to drop table LOG');
END IF;
EXECUTE IMMEDIATE '
CREATE TABLE LOG (
Id numeric(19,0) NOT NULL,
CreateDate timestamp default sysdate NOT NULL,
Thread varchar (510) NULL,
LogLevel varchar (100) NULL,
Logger varchar (510) NULL,
Message varchar (4000) NULL,
InnerException varchar (4000) NULL,
CONSTRAINT PK_LOG PRIMARY KEY (Id)
COMMIT;
dbms_output.put_line('table LOG created');
dbms_output.put_line('setup complete');
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('*** setup exception detected! ***');
dbms_output.put_line('error code: ' || sqlcode);
dbms_output.put_line('stack trace: ' || dbms_utility.format_error_backtrace);
RAISE_APPLICATION_ERROR(-20000, 'AuditTrail.oracle.tables.sql - install failed');
END;
Before running script, make sure your account has permission (unless you're using SYS account of course). You'd probably need to know how to create user and granther right:
CREATE USER dev IDENTIFIED BY "devacc_@";
GRANT CREATE SESSION TO DEV;
GRANT DBA TO DEV;
Here's how you can run PL\SQL scripts in Oracle
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 6 14:10:05 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> connect devvvy/"somepwd"
Connected.
SQL> set serveroutput on
SQL> @C:\dev\UnitTest\Util\Command\sql\Oracle\SetupSchema\xxxxx.oracle.tables.sql
1125 /
SQL> @C:\dev\Util\Command\sql\Oracle\SetupSchema\xxxxx.oracle.tables.data.only.sql
560 /
PL/SQL procedure successfully completed.
SQL> @C:\dev\Util\Command\sql\Oracle\SetupSchema\AuditTrail.oracle.tables.sql
54 /
PL/SQL procedure successfully completed.
SQL> COMMIT;
Remeber however:
(a) SQL*Plus does not like "&" in your SQL script. Do comment or string containing "&" should be taken out.
(b) password should not contain "@" because it's a special character in "CONNECT" command.
Alternative, download TOAD for Oracle - http://www.toadsoft.com/toad_oracle.htm
(c) After command, type "/" next line to get command executed.
(d) remember to COMMIT
REF for Oracle:
Oracle Official doc: http://www.oracle.com/pls/db111/portal.portal_db?selected=1&frame=
Oracle 11g configuration Guide: http://www.thegeekstuff.com/2008/10/oracle-11g-step-by-step-installation-guide-with-screenshots/
ODAC/ODP.NET QuickStart: http://www.installationwiki.org/ODP.NET_Getting_Started_Guide
ODP.NET versioning scheme: http://download.oracle.com/docs/html/E10927_01/InstallVersioningScheme.htm
SQLPlus basic: http://download.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25108/xedev_sqlplus.htm#CJAGGHGE
PL\SQL:
Cheat sheet: http://en.wikibooks.org/wiki/Oracle_Programming/SQL_Cheatsheet
Reference:
http://www.rocket99.com/techref/oracle_plsql.html
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
EXECUTE IMMEDIATE, DROP/CREATE TABLE: http://www.java2s.com/Code/Oracle/PL-SQL/Callexecuteimmediatetodroptablecreatetableandinsertdata.htm
Exception handling: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/07_errs.htm
Named Block syntax: http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/Thestructureofanamedblock.htm
CREATE PROCEDURE: http://it.toolbox.com/blogs/oracle-guide/learn-plsql-procedures-and-functions-13030
Oracle DataType: http://www.ss64.com/orasyntax/datatypes.html
http://www.adp-gmbh.ch/ora/misc/datatypes/index.html
Oracle Sequence and Create table: http://www.java2s.com/Tutorial/Oracle/0100__Sequences/Usingasequencetopopulateatablescolumn.htm
Similar Messages
-
How to connect to Oracle database from webdynprojava application
Hi
How to connect to Oracle database from webdynprojava application. where can we provide the code to connect to database.?
Thank You.Hi,
You need to create Java Bean model. The bean is a typical java bean with default constructor, getter and setter. You can have additional methods for query etc. The attributes in the class will be your model node and attributes.
However you need to configure the connection and create JNDI using visual administrator before writing the code.
You can also consider writing Session EJB with oracle and using them in WD.
http://help.sap.com/saphelp_nwce10/helpdata/en/45/dcaa4f05535591e10000000a1553f7/frameset.htm
Srini -
Oracle Application server connection pool and database links
I am using Oracle application server 10g with connection pools, the db used by the application connects to another oracle db using a database link. My question is when the application starts it creates 10 connections, does it also create x amount of database links as well?
Hi,
Is there any way to use the connection pool or Datasource while connecting to database?If I am using a stateless sesssion bean and using a Data Access layer which just creates a database session to write the persistence toplink objects how I can make use of application server connection pool?Hi Vinod,
Yes, TopLink allows you to use the app server's connection pooling and transaction services. Chapter 2 of the Oracle9iAS TopLink Foundation Library Guide provides details as do the TopLink examples. The easiest way to set this up is by using the sessions.xml file. The sample XML below is from the file <toplink903>\examples\ias\examples\ejb\sessionbean\sessions.xml. Here we are adding the datasource defined in OC4J and specifying that we are using the OC4J transaction controller also.
<login>
<user-name>sa</user-name>
<password></password>
<datasource>java:comp/env/jdbc/ejbJTSDataSource</datasource>
<uses-external-transaction-controller>true</uses-external-transaction-controller>
<uses-external-connection-pool>true</uses-external-connection-pool>
</login>
<external-transaction-controller-class>oracle.toplink.jts.oracle9i.Oracle9iJTSExternalTransactionController</external-transaction-controller-class>
When using this approach you need to change your TopLink code slightly in the EJB methods:
a. Acquire the ACTIVE unit of work from the server
session (again, see the EmployeeSessionEJB code
example) with something like:
UnitOfWork uow = clientSession.getActiveUnitOfWork();
b. Calls to uow.commit() can be ommitted or commented out
because the EJB will handle this. Note that of course
the methods you create in the EJB that are using this
approach must have TX Required (default).
Hope this helps.
Pete -
Help needed in connecting to oracle database in unity
Hi,
I have been trying to connect to Oracle database in my codes. I have tried using OdbcConnection and OleDbconnection. But both did not allowed me to connect to the database. The database, testDb, can be accessed using SQL plus as well as the SQL developer. I even tested the connection successful using ODBC data source administrator.
the following is my code for the connection string:
OdbcConnection connectionString = "Driver={Oracle ODBC Driver};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP )(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SID=Te stDb)));Uid=scott;Pwd=password;";
the error i got is [ODBC Driver Manager] Data Source name not found and no default driver specified.
for the driver parameter, i have tried using "Microsoft ODBC for Oracle". It gives me another error stating that the oracle and network components are not installed.
I even tried "Oracle in OraDb11g_home1" which was specified in the ODBC Data Source Administrator. The same error came out.
Below are some of my specifications:
Platform: Windows 7 64bit
Oracle: Oracle Database 11g Release 2 (64bit)
Unity: 4.1.2
Can someone please help me with this? What is it that i have done wrong?
Thanks.1008737 wrote:
Hi,
I have been trying to connect to Oracle database in my codes. I have tried using OdbcConnection and OleDbconnection. But both did not allowed me to connect to the database. The database, testDb, can be accessed using SQL plus as well as the SQL developer. I even tested the connection successful using ODBC data source administrator.
the following is my code for the connection string:
OdbcConnection connectionString = "Driver={Oracle ODBC Driver};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP )(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SID=Te stDb)));Uid=scott;Pwd=password;";
whenever localhost (127.0.0.1) is used, this means that no remote client can ever connect to this system
The problem involves ODBC configuration & has nothing to do with Oracle. -
Using php to connect to Oracle Database 11g Release 2 Enterprise Edition
Greetings everyone!
Please i dont know how to connect to Oracle Database 11g Release 2 Enterprise Edition with php even though i connected with php successfully with Oracle Database 11g Express Edition with the php code below. can someone help please...
define('ORA_CON_UN', 'hr'); // User name
define('ORA_CON_PW', 'Adlibs14$'); // Password
define('ORA_CON_DB', '//localhost/XE'); // Connection identifier
// use constants defined in anyco_cn.inc
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
if (!$conn) {
db_error(null, __FILE__, __LINE__);
Edited by: user11273096 on Jul 14, 2011 3:41 PMNote that this forum is for XE Beta, not EE.
Can you connect from some other client tool, such as sqlplus?
There's a {forum:id=178} forum that may be more suitable, if basic connectivity outside php works (i.e. issue is only php specific). -
Using php to connect to Oracle Database 11g Release 2 Enterprise Edition EE
Greetings everyone!
Please i dont know how to connect to Oracle Database 11g Release 2 Enterprise Edition with php even though i connected with php successfully with Oracle Database 11g Express Edition with the php code below. can someone help please...Note im referring to oracle EE not XE.
define('ORA_CON_UN', 'hr'); // User name
define('ORA_CON_PW', 'Adlibs14$'); // Password
define('ORA_CON_DB', '//localhost/EE'); // Connection identifier
// use constants defined in anyco_cn.inc
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
if (!$conn) {
db_error(null, __FILE__, __LINE__);
Edited by: user11273096 on Jul 15, 2011 12:03 AMFind the hostname and service name of the database and use those values in the ORA_CON_DB constant.
Use 'lsnrctl status' on the database host to find the service name.
If you use a "tns" alias, you may need to create a tnsnames.ora file where PHP can access it.
Set the environment variable TNS_ADMIN (on Linux) to the directory containing the file.
See the section "Oracle Database Name Connection Identifiers" p 102 of the free book
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html -
Connect to oracle database using c program
I am using AIX environment and i want to connect to oracle database using c program.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10825/pc_03dbc.htm#i5880
-
Cant connect to Oracle database using oracle db client
Hi All,
I recently created a virtual machine running windows server 2008 on my windows 7 host. Oracle database 11g is already installed on host OS(windows 7) and I have installed oracle 11g client on the guest OS(windows server 2008) and trying to connect to oracle database from remote server using oracle client but getting this error:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATAI am trying to connect using oracle client as below:
C:\Users\Administrator>SET ORACLE_SID = HR84DEV
C:\Users\Administrator>SQLPLUS /NOLOG
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 10 06:16:34 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> CONNECT SYSADM/[email protected]
ERROR:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
I have created database with name - HR84DEV
HOST ip address is - 192.168.56.1
I googled this error and as most of resources/blogs talked about having correct entry on listner.ora and tnsnames.ora file, I did the changes on both of these files accordingly.
PFB the cotent of both of these files:
tnsnames.ora
# tnsnames.ora Network Configuration File: C:\MyApps\Oracle\product\11.2.0\dbhome_\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
HR84DEV =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = HR84DEV)
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
listner.ora
# listener.ora Network Configuration File: C:\MyApps\Oracle\product\11.2.0\dbhome_\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\MyApps\Oracle\product\11.2.0\dbhome_)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\MyApps\Oracle\product\11.2.0\dbhome_\bin\oraclr11.dll")
(SID_DESC =
(SID_NAME = HR84DEV)
(ORACLE_HOME = C:\MyApps\Oracle\product\11.2.0\dbhome_)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\MyApps\Oracle\product\11.2.0\dbhome_\bin\oraclr11.dll")
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
ADR_BASE_LISTENER = C:\MyApps\Oracle
Please not that I dont have any problem in connect to database locally.Thanks Nicolas,
Actually, there was a problem with my oracle client installation. I uninstalled it and then installed back again but still, even after following your instructions I get some error.
Here what I did:
Created tnsnames.ora file as below:
HR84DEV =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = HR84DEV)
Placed it under appropriate directory and then checked the connection with database using the command shown below:
C:\Users\Administrator>tnsping HR84DEV
TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 10-FEB-2
012 08:42:03
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
C:\MyApps\Administrator\product\11.2.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.56.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = HR84DEV)))
OK (20 msec)
Then tried to connect to database as below:
C:\Users\Administrator>SET ORACLE_SID=HR84DEV
C:\Users\Administrator>SQLPLUS /NOLOG
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 10 08:25:56 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> CONNECT SYSADM/SYSADM@HR84DEV
ERROR:
ORA-28547: connection to server failed, probable Oracle Net admin error
But still getting error.
I Googled this error and tried to figure out what the problem is and came across the possible cause which is because I haven't specify that the service should run as a user who is in domain admin group.
well, I am not really sure about this and dont know what user name and password I should enter in OracleserviceHR84DEV-properties-log on-this account.
do I really need to set this? -
I cannot create an Application server connection in Oracle JDeveloper 11 g
i cannot create an Application server connection in Oracle JDeveloper 11 g , i got 0 of 9 test successful and i got this erros
Cannot establish connection.
Testing JSR-160 DomainRuntime ... skipped.
Testing JSR-88 ... skipped.
Testing JSR-88-LOCAL ... skipped.
Testing JNDI ... skipped.
Testing JSR-160 Edit ... skipped.
Testing HTTP ... failed.
Testing Server MBeans Model ... skipped.
Testing HTTP Authentication failed
0 of 9 tests successful.Hi,
you can start the Jdev by command line and then see the log that it is generating. Maybe there you can see the problem that is happening.
Also you can check if the server is running with
telnet hostname 7001
Some possible reasons
you have a firewall blocking the connection
did you check /etc/hosts file entry ? should be something like this <ip address of host > hostname1
Cheers
Augusto -
Hello,
I am trying to connect to oracle database 10.1.0.2.0 from jdeveloper 11.1.2.1.0 to develop an ADF application.
But it is giving me the error
Test failed: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
connection type:oracle(JDBC)
Role :SYSDBA
Driver:thin
Host:localhost
JDBC port:1521
SID:webaid
I am able to connect to the database using SQL*Plus with the same credentials.
Any help is appreciated!I take it you solved this problem, since you posted this: installing Oracle 10.1.0.2.0 (32 bit) on windows 2003 server
-
Connect to Oracle database from SQL Sever
Can you help on an issue of connection from SQL Server to Oracle database:
In SQL Server, I create a "linked server" to connect to Oracle database on a different machine. But it will take a unreasonable time (about 30 seconds) to call a Oracle query from SQL Server.No there are no entries required in the TNSNAMES.ORA
When you are using ODBC for connection, Oracle does not look fo rany enteries in TNSNAMES.ORA file.
Now I am able to connect to both SQL Plus and Forms 6i. But while connecting to SQL Plus its giving an error
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Server not available or version too low for this feature
Connected to:
Oracle Open Client Adapter for ODBC 6.0.5.35.0
Microsoft SQL Server 08.00.0534
Also while disconnecting the Windows Program Error comes, and the application closes abruptly. -
Could not connect to Oracle database from excel macro. Getting connection not open.
Hi all,
I could not connect to oracle database using excel macro. After much R&D also, I cannot find right solution. Please help me where I am doing wrong.
Sub Button2_Click()
Dim Conn As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim Cmd As New ADODB.Command
Dim sqlText As String
Dim Row As Long
Dim Findex As Long
Dim Data As Worksheet
Dim X As Long
Dim UID As String
Dim PWD As String
Dim Server As String
Dim strCon As String
Application.Calculation = xlCalculationManual
UID = "myUserid" 'Enter the User ID
PWD = "myPassword" 'Enter the password
Server = "myHostname or myServername"
Set Data = Sheets("Sheet2")
Data.Select
Range("A:J").ClearContents
strCon1 = "Provider = Microsoft.ACE.OLEDB.12.0;DATA SOURCE=myHostName;Database=myDBname;uid=myUserid;pwd=myPassword;"
Conn.Open (strCon1)
Cmd.ActiveConnection = Conn
Cmd.CommandType = adCmdText
' Put your query next
sqlText = " select * from table "
Cmd.CommandText = sqlText
Set RS = Cmd.Execute
For X = 0 To 17
Data.Cells(1, X + 1) = RS.Fields(X).Name
Next
Do While Not RS.EOF 'this loops through the data and puts it in the spreadsheet
Row = Row + 1
For Findex = 0 To RS.Fields.Count - 1
Data.Cells(Row + 1, Findex + 1) = RS.Fields(Findex).Value
Next Findex
RS.MoveNext
Loop
Application.Calculation = xlCalculationAutomatic
Application.Calculate
End Sub
sammyI have set oci.dll in to the path specified. Prior to this I musy say that, I have 64 bit excel 2010 & installed respective drivers from the link provided http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html
But
still I am facing as:-" Provider cannot be found. It may not be properly installed."
sammy -
Not able to connect remote oracle database over VPN
I can not connect remote oracle database over VPN. tnsping is ok and it shows the server information of remote database. i can also telnet the 1521 port of remote database server. I can connect the same server when it is located in the same LAN. Please help me out this is very urgent.
6b6c669e-6baa-45c4-a6dc-444aef2d5e7a wrote:
I can not connect remote oracle database over VPN. tnsping is ok and it shows the server information of remote database. i can also telnet the 1521 port of remote database server. I can connect the same server when it is located in the same LAN. Please help me out this is very urgent.
First, this is a forum of volunteers. There is no "urgent" here.
"Urgent" means one of two things -
1) people are dying, or
2) you have a customer-facing, revenue-producing production system that is down.
(And to get some perspective on the second case, keep the first in mind.)
For the first, you call whatever civil emergency service seems appropriate.
For the second, you open an SR with Oracle - which requires a paid-up support contract. For *them* to consider your problem "urgent", you will need to demonstrate that your problem falls under item #2. I seriously doubt your problem fits that criteria.
You don't have a support contract? Now you know the exact dollar figure that your company places on the data.
That said, you need to understand a few things about your specific problem,
First, port 1521 is only used by the listener to accept a connection request. Once it gets that request (and finds that it is for a service (sid) that it knows about, it will fork a server process and tell the requesting client that it can communicate with that server process over some other port .. a randomly chosen port number in the "high" range. It could be your vpn is blocking that other port, whereas your internal firewall is not.
But this is just an educated guess since I cannot find "can not connect remote oracle database over VPN" in any error message manual. If you had mentioned the VPN along with an actual oracle error message we could be much more precise in our diagnoses and recommendations.
---- edit 22 Sep
It occurred to me that I just assumed you were using the same client machine in both cases ... a laptop that you use both at work (local network) and home (vpn). If that assumption is false, there are probably problems with your tns setup on the home (vpn) machine.
But again, it would be much easier to help if you gave us an actual error message. -
Unable to connect to Oracle database running on Windows machine from linux.
Hi,
I'm not able to connect to oracle database running on Windows machine from Linux machine. I'm geting the below mentioned error. I have given below the code I used to connect to database and database propertes.Do I need to use any specific driver?
Please help me.
Thanks,
Sunjyoti
Code :
import oracle.jdbc.pool.OracleDataSource;
import java.sql.Connection;
import java.util.*;
import java.sql.*;
import java.io.*;
class try2{
public static void main(String args[]) {
try {
System.out.println("hi");
// Load the properties file to get the connection information
Properties prop = new Properties();
prop.load(new FileInputStream("/home/sreejith/EDIReader/Connection.properties"));
// Create a OracleDataSource instance
OracleDataSource ods = new OracleDataSource();
System.out.println("prop is "+prop);
configureDataSource(ods, prop);
Connection conn=null;
// Create a connection object
conn = ods.getConnection();
System.out.println("Connection is"+conn);
// Sets the auto-commit property for the connection to be false.
conn.setAutoCommit(false);
} catch (SQLException sqlEx){ // Handle SQL Errors
System.out.println("In exception "+sqlEx);
} catch(Exception excep) { // Handle other errors
System.out.println(" Exception "+ excep.toString());
private static void configureDataSource(OracleDataSource ods, Properties prop) {
// Database Host Name
ods.setServerName(prop.getProperty("HostName"));
// Set the database SID
ods.setDatabaseName(prop.getProperty("SID"));
// Set database port
ods.setPortNumber( new Integer( prop.getProperty("Port") ).intValue());
// Set the driver type
ods.setDriverType ("thin");
// Sets the user name
ods.setUser(prop.getProperty("UserName"));
// Sets the password
ods.setPassword(prop.getProperty("Password"));
Connection properties :
# Your Database Connection details
HostName = 10.20.3.19
SID = EDIREAD
Port = 1521
UserName = dbuser
Password = dbuser
Error I'm getting is
error while trying to connect with odbc datasource
[root@iflexpau2217 EDIReader]# java try2
hi
prop is {HostName=10.20.3.19, Password=dbuser, UserName=dbuser, SID=EDIREAD, Port=1521}
In exception java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
Also I tried to connect with weblogic JDBC driver
Code is here:
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
//import com.entrust.toolkit.util.ByteArray;
public class trial{
public static void main(String args[]) throws IOException{
System.out.println("hi");
Connection p_conn = null;
PreparedStatement xml_insert = null;
try {
// Load the JDBC driver
System.out.println("hi2");
// String driverName = "oracle.jdbc.driver.OracleDriver";
String driverName = "weblogic.jdbc.oracle.OracleDriver";
System.out.println("hi2");
Class.forName(driverName);
// Create a connection to the database
String serverName = "10.20.3.19";
String portNumber = "1521";
String sid = "EDIREAD";
//String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String url = "jdbc:bea:oracle://10.20.3.19:1521";
String username = "dbuser";
String password = "dbuser";
System.out.println("connection is:"+p_conn+"user name is"+username+"password is"+password);
p_conn = DriverManager.getConnection(url, username, password);
System.out.println("connection is:"+p_conn+"user name is"+username+"password is"+password);
xml_insert=p_conn.prepareStatement("insert into PRTB_SUBUNIT (SUBUNT_ID,SUBUNT_SUB_UNIT,SUBUNT_PHYUNT_ID) values (?,?,?)");
//InputStream in=null;
File l_file=new File("/home/sreejith/EDIReader/propertyfiles/inputfile/BUG_10802_ES_CSB19_68.txt");
BufferedReader input =null;
input=new BufferedReader(new FileReader(l_file));
String line = null;
StringBuffer trial=new StringBuffer();
while (( line = input.readLine()) != null){
trial.append(line);
trial.append(System.getProperty("line.separator"));
//InputStream is = new BufferedInputStream(new FileInputStream(l_file));
System.out.println(trial.toString());
//Blob b ;
//byte[] bytes=trial.toString().getBytes();
//System.out.println("Size-->"+bytes.length);
xml_insert.setString(1,new String("SpecailChar"));
//xml_insert.setBinaryStream(2,new ByteArrayInputStream(bytes),15920);
xml_insert.setString(3,"SpecailChar");
xml_insert.executeUpdate();
p_conn.commit();
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException:"+e.getMessage());
// Could not find the database driver
} catch (SQLException e) {
System.out.println("SQEXCEPTIN:"+e.getMessage());
// Could not connect to the database
}catch (FileNotFoundException e) {
System.out.println("filenot found:"+e.getMessage());
// Could not connect to the database
Error I'm getting is
error while trying with jdbc:
SQEXCEPTIN:[BEA][Oracle JDBC Driver]Error establishing socket to host and port: 10.20.3.19:1521. Reason: Connection refusedIs the Windows firewall active? Have you enabled the port on the firewall, if it is?
-
Using JDBC Adapter posting data from Oracle database to Falt file????
Hi All,
By using JDBC adapter, for now I have to connect to Oracle Database and then get the employee information from the Employee Table and post it to the flat file, can you please help me out the complete procedure...
Thanks in advance
AndyHi Andy,
have a look at the help for configuring a JDBC Sender adapter: http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
It mentions all the settings you'll need to make e.g. the connection URL as posted above.
And it also lists how an XML file looks like that contains the query results according to the SQL Select statement in the adapter.
<resultset>
<row>
<column-name1>column-value</ column-name1>
<column-name2>column-value</ column-name2>
<column-name3>column-value</ column-name3>
</row>
<row>
<column-name1>column-value</ column-name1>
<column-name2>column-value</ column-name2>
<column-name3>column-value</ column-name3>
</row>
</resultset>
So you have to create a datatype, message type and message interface to match this structure (of course you'll need to substitute column-name1 etc. with the column names in your select statement).
Now if you want to create a flat file from that, you have to create an XML representation of that flat file and use the content conversion in the receiver file adapter as defined here: http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm
Regards
Christine
Maybe you are looking for
-
Hi guys, I am developing an integration with EWS based on php. I am using a library I found https://github.com/jamesiarmes/php-ews In my case users have various calendars hanging from the root, I get access to the default calendar by this: $request->
-
My Macbook pro is about 3 or 4 years old. It has never given me trouble. All of the sudden the last 2 weeks it has been getting slow. Its progressivley getting worse I can barely type without it pausing and giving me the wheel. I can't multitask and
-
Keynote crashes and then corrupts the file
I hoping somebody can help --- this is driving me crazy. When editing an existing document in Keynote 9.3 at some point it crashes and I have to force quit. When I restart my document is corrupted (the graphics thumbnails appear, but the graphisc on
-
last night I opened the ipad 2 it worked fine today the seri does noe work the app for taking a photo does not exist nor does photoshop and the app store app is gone as well
-
Im getting an error message "the backup volume could not be mounted"
I'm getting an error message "the backup volume could not be mounted"