fiogf49gjkf0d
Ever wish there was an easier way to get views created in Remotes? Looking to push out a non-SLXOLEDB compliant Transact SQL statement? Use the following function in a VB Script and it work on any remote that falls under the following rules:
- The remote is using msdb (MSSQL) as the database platform.
- The remote was attached via the standard SLX attach database utility
Function ExecuteMySQL(strSQL, strSQLObject, strObjectType, strAction)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ADO constants and variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const adCmdText = 1
Const adCmdTable = 2
Const adCmdStoredProc = 4
Const adCmdUnknown = 8
Const adOptionUnspecified = 1
Const adExecuteNoRecords = 128
Const adExecuteRecord = 512
Const adChar = 129
Const adDate = 7
Const adParamInput = 1
Const adParamOutput = 2
Dim sADOConnStr
Dim oADOConn
Dim rs
Dim lstrSQL
Const SQLUserId = "sysdba"
Const SQLPwd = "masterkey"
Const SQLServerName = "127.0.0.1,1433"
Const SQLSourceDBName = "Slxremote"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Establish ADO connection to Saleslogix remote database
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sADOConnStr = "Provider=SQLOLEDB;Data Source=" & SQLServerName & ";Initial Catalog=" & SQLSourceDBName & _
";user id=" & SQLUserId & ";password=" & SQLPwd & ";"
Set oADOConn = CreateObject("ADODB.Connection")
oADOConn.ConnectionString = sADOConnStr
oADOconn.Open
oADOconn.CommandTimeOut = 0
lstrSQL = "select Name from dbo.sysobjects where id = object_id(N'" & Ucase(strSQLObject) & "') and " & _
"OBJECTPROPERTY(id, N'Is" & strObjectType & "') = 1"
Set rs=oADOConn.execute(lstrSQL)
If rs.EOF = False And strAction = "Create" Then
lstrSQL = "Drop " & strObjectType & " " & strSQLObject
oADOconn.execute lstrSQL
oADOconn.Execute strSQL
Else
If rs.EOF = True And strAction = "Create" Then
oADOconn.Execute strSQL
End If
End If
If rs.EOF = False And strAction = "Drop" Then
oADOconn.Execute strSQL
End If
If strAction = "Execute" And strSQL <> "" Then
oADOconn.Execute strSQL
End If
If rs.EOF = True Then
ExecuteMySQL = 0
Else
ExecuteMySQL = 1
End If
rs.Close
oADOconn.Close
Set rs = Nothing
Set oADOConn = Nothing
End Function
Sub Main
If UCase(Application.BasicFunctions.SystemInfoFor("DataBaseNames")) = "SLXREMOTE" Then
strSQLObject = "sysdba.MYVIEW"
strSQL = ""
strObjectType = "view"
strAction = "Execute"
If ExecuteMySQL(strsql, strSQLObject, strObjectType, strAction) < 1 Then
strSQLObject = "sysdba.MYVIEW"
strSQL = "Create View sysdba.myview as Select Accountid as RecordId from sysdba.Account " & _
"UNION ALL Select ContactId as RecordId from sysdba.Contact"
strObjectType = "view"
strAction = "Create"
intNoAction = ExecuteMySQL(strsql, strSQLObject, strObjectType, strAction)
End If
End If
End Sub