QTP automated testing - connect to the database

Connection String

'========================================
' Name: get_ConnectorStr
'effect: Get connected string
'parameter: = MySQL. 1; 2 = SQLServer; Oracle. 3
' return value: connection string
'call: msgbox get_ConnectorStr ( "type database")
' ================ ========================
Function get_ConnectorStr (strType)
Dim strCnn
the If the Then strType. 1 =
'MySQL
DATABASE = testwin;; strCnn = "the DSN = testmysqlforqtp the PWD 123 =; PORT = 3306; SERVER = 192.168.1.75; the UID = the root "
ElseIf strType = 2 the Then
strCnn =" the Data .; the Initial Cataog the Source = = testdata66; the Persist Security Info = True; the User ID = SA; PassWord = 123 "
the If End

get_ConnectorStr = strCnn
End Function

1 sqlserver database

Dim ConnectionString,SqlConnection,SqlCommand,SqlDataAdapter,DataSet
ConnectionString=get_ConnectorStr("2")
Set SqlConnection=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlConnection","System.Data",ConnectionString)
SqlConnection.Open
Set SqlCommand=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlCommand","System.Data","select * from tbinfopart",SqlConnection)
Set SqlDataAdapter=DotNetFactory.CreateInstance("System.Data.SqlClient.SqlDataAdapter","System.Data",SqlCommand)
Set DataSet=DotNetFactory.CreateInstance("System.Data.DataSet","System.Data")
SqlDataAdapter.Fill DataSet
SqlConnection.Close
MsgBox DataSet.Tables.get_Item(0).Rows.Count

 

Guess you like

Origin www.cnblogs.com/caojuansh/p/10938245.html