Micro Focus QTP (UFT) Forums
Database connection - TNS error - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Database connection - TNS error (/Thread-Database-connection-TNS-error)



Database connection - TNS error - Shwetha - 05-20-2011

Hi ,

I am getting TNS protocol error when i try to connect to Oracle database.Please any one help me to resolve this issue

I am using below code,


Code:
Public Function Action_Open_Oracle_Database_Connection(sDbHost,sDbSID,sDbUserName,sDbUserPassword,sDbProtocol,sDbPort,sQuery,FieldName)
   'Creates a DB connection object and opens the connection

                                Set  DB_CONNECTION=CreateObject("ADODB.Connection")
                               sConnection_String = "Driver={Oracle in OraClient11g_home1}; " &_
                                "CONNECTSTRING=(DESCRIPTION=" &_
                                "(ADDRESS=(PROTOCOL=" & sDbProtocol & ")"&_
                                "(HOST="& sDbHost &")(PORT=" & sDbPort & "))"&_
                                "(CONNECT_DATA=(SID=" & sDbSID & "))); uid=" & sDbUserName & ";pwd=" & sDbUserPassword & ";"

                                DB_CONNECTION.Open sConnection_String

                                'Action_Open_Oracle_Database_Connection = DB_CONNECTION

set Record_Set1=DB_CONNECTION.Execute(sQuery)
row_value1 = Record_Set1.FIELDS(FieldName)

''Rec.open sQuery ,conn
'
'UN= Rec.fields(FieldName)
msgbox row_value1
End Function



RE: Database connection - TNS error - lalithome - 05-23-2011

Hi
Brfore i Start to dig can u confirm that oracle client is installed on ur machine and ur able to connect to DB using client

lalit


RE: Database connection - TNS error - surya_7mar - 05-24-2011

I am using below and i am able to getdata from oracle.we need to have oracle installed in the machine to run this

Code:
Dim sDataSource
sDataSource = envDBInstance
Dim strConnection, oDbConn, rs, strSQL
    
strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & sDataSource & ";User Id=user;Password=password;"

on Error Resume Next

    Set oDbConn = CreateObject("ADODB.Connection")
    oDbConn.Open strConnection
    
     Set oResultSet = CreateObject("ADODB.recordset")
    oResultSet.open sQuery, oDbConn, 3,3