新服务器& SQL安装 - VBScript代理作业需要6倍的时间

时间:2016-06-14 08:08:33

标签: sql sql-server vbscript agent

我们有一个非生产环境服务器,用于将我们的所有数据从主数据库迁移到新服务器。

我们正在迁移:

  

Microsoft SQL Server 2008(SP3) - 10.0.5520.0(Intel X86)2014年7月11日   12:30:03版权所有(c)1988-2008 Microsoft Corporation Standard   Windows NT 5.2(Build 3790:Service Pack 2)上的版本

要:

  

Microsoft SQL Server 2008 R2(SP3) - 10.50.6220.0(X64)2015年3月19日   12:32:14版权所有(c)Microsoft Corporation标准版   Windows NT 6.3(Build 9600:)(管理程序)

上的(64位)

到目前为止,我们遇到的最大问题是我们在IBM AIX环境中有一个数据库,我们需要每隔20分钟将每日数据库转储到单个数据库。在当前的生产服务器上,这非常好用,但在新配置(非生产)上,它需要花费6倍的时间,实际上是2小时!

我不知道从哪里开始寻找这样的原因。

它通过VBScript编写脚本,因为它需要将一组表从AIX环境复制到SQL。我们知道没有其他方法可以访问数据。

我们设法解决x86和x64之间的驱动程序问题,但在此之前,我们设法使用适当风格的CScript运行.VBS文件,以确保x64驱动程序不会导致问题。这也需要2个小时,这就是为什么我们设法试用了正确的驱动程序,但仍然需要一段时间。

这是一个奇怪的问题,并且可能对许多问题持开放态度,但任何建议都会被感激地接受!

arrTableList = Array ("array","of","tables")
sSQLConn = "DSN=[New SQL Server]; UID=[username];PWD=[password];DATABASE=[DBName];"
sUniplanConn = "DSN=[USQL Database].udd;"

Const adCmdText = &H1
Const adUseClient = 3
Const adCmdStoredProc = &H4
Const adParamInput = &H1
Const adChar = 129
Const adExecuteNoRecords = &H80

Set ConnectConn = CreateObject("ADODB.Connection")
ConnectConn.Open sSQLConn

Set rst = CreateObject("ADODB.Recordset")
rst.ActiveConnection = sUniplanConn

For j = 0 To UBound(arrTableList)
    sTableName = arrTableList(j)

    start = timer()

    sSQL = "select * from " & sTableName 
    rst.source = sSQL
    rst.CursorType = 0
    rst.CursorLocation = 2
    rst.LockType = 3
    rst.Open

    Set cmd = CreateObject("ADODB.Command")
    cmd.ActiveConnection = sSQLConn
    cmd.ActiveConnection.CursorLocation = adUseClient
    cmd.CommandTimeout = 0

    sSQL = "EXEC ADODBRecordsetImport 1"
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    cmd.Execute , , adExecuteNoRecords

    For Each Field In rst.Fields
        'Debug.Print Field.Type & vbTab & Field.DefinedSize & vbTab & Field.Name
        sSQL = "INSERT INTO Temp_Recordset_Schema " _
                & "SELECT '" & sTableName & "_Import','" & Field.Name & "','" & Field.Type & "','" & Field.DefinedSize & "'"
        cmd.CommandText = sSQL
        cmd.CommandType = adCmdText
        cmd.Execute , , adExecuteNoRecords
    Next

    sSQL = "EXEC ADODBRecordsetImport 2"
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    cmd.Execute , , adExecuteNoRecords


    sSQL = "BEGIN TRANSACTION"
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    cmd.Execute , , adExecuteNoRecords


    Do Until rst.EOF
        sSQL = "INSERT INTO " & sTableName & "_Import VALUES("
        For n = 0 To rst.Fields.Count - 1
            sFieldValue = rst(n)
            'Debug.Print rst(n) & vbTab & rst(n).Type

            If IsNull(rst(n)) Then
                sSQL = sSQL & "Null,"
            Else
                If rst(n).Type = 133 Then sFieldValue = FormatDateTime(sFieldValue, 1)
                sSQL = sSQL & "'" & Replace(sFieldValue, "'", "''") & "',"
            End If
        Next
        sSQL = sSQL & ")"
        sSQL = Replace(sSQL, ",)", ")")
        'Debug.Print sSQL
        cmd.CommandText = sSQL
        cmd.CommandType = adCmdText
        cmd.Execute , , adExecuteNoRecords
        rst.MoveNext
    Loop

    sSQL = "COMMIT"
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    cmd.Execute , , adExecuteNoRecords

    sSQL = "TRUNCATE TABLE " & sTableName
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText
    cmd.Execute , , adExecuteNoRecords



    sSQL = "INSERT INTO " & sTableName & " SELECT * FROM " & sTableName & "_Import"
    cmd.CommandText = sSQL
    cmd.CommandType = adCmdText

    cmd.Execute , , adExecuteNoRecords

    rst.Close

    start = Timer() - start
    ConnectConn.execute "INSERT INTO Connect.dbo.updatetimes ([Table],[Time]) VALUES ('" & sTableName & "'," & start & ")"
Next

Set cmd = Nothing
Set rst = Nothing

0 个答案:

没有答案