insertion problems - Please Help!!!

  • hello all

    I am writing codes in VBScript using the WSH to fetch select system parameters from Win32 Classes. Below specified is my code.

    'ADODB Connection

    Dim AdCn

    'SQL Query string

    Dim SQL, SQL_DiskDtls

    'ADODB Recordset

    Dim adrec2

    Set AdCn = CreateObject("ADODB.Connection") ' Creates the connection object

    Set AdRec2 = CreateObject("ADODB.Recordset") ' Creates the recordset object

    'variable for holding cpu load

    dim cpuload

    'memory\pages/second

    dim ppsec

    'Update COnnection string with you servername, databasename, login and password.

    connstring = "Provider=SQLOLEDB;Data Source=TCS044679;Initial Catalog=ServerCPUUsage;user id = 'cpuusageuser';password='cpuusageuser' "

    AdCn.Open = connstring

    ' This section is to fetch the computer name

    Set WshNetwork = WScript.CreateObject("WScript.Network")

    Computer =  WshNetwork.ComputerName

    Set wbemServices = GetObject("winmgmts:\\" & Computer)

    'physical memory object set

    Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")

    'cpu load object set

    Set wbemcpuloadSet = wbemservices.InstancesOf ("Win32_Processor")

    'pages per sec obj set

    Set wbempagepsecSet = wbemservices.InstancesOf("Win32_PerfRawData_PerfOS_Memory")

    'Object set for fetching the disk details:

    Set wbemDiskDtls = wbemservices.InstancesOf("Win32_LogicalDisk")

    'avg disk queue length

    'This section fetches the CPU LOAD and CPU ID/NAME:

    For Each wbemcpuload in wbemcpuloadSet

     cpuid = wbemcpuload.deviceid

     cpuload = wbemcpuload.Loadpercentage 

    next

    'This section is used to fetch the Pages per second:

    For each wbempagepsec in wbempagepsecSet

     ppsec = wbempagepsec.PagesPerSec

    next

     

    'This section is used to fetch the disk details:

    For each wbemDiskDtl in WbemDiskDtls

     Disk_ID = wbemDiskDtl.DeviceID

     Disk_Name= wbemDiskDtl.Name

     Disk_Frmt= wbemDiskDtl.FileSystem

     Disk_Cmprssd = wbemDiskDtl.Compressed

            If Disk_Cmprssd = False then

            Disk_Cmprssd1 = N

            else

            Disk_Cmprssd1 = Y

            end if

     Disk_Size = wbemDiskDtl.Size

     Disk_Free = wbemDiskDtl.FreeSpace

     Disk_Used = Disk_Size - Disk_Free

    next

    SQL_DiskDtls = "INSERT INTO LL_DISK_DTLS(Server_Name, Disk_ID, Disk_Name, Disk_Frmt, Disk_Cmprssd, Disk_Size, Disk_Free, Disk_Used) select '" & Computer & "','" & Disk_ID & "','" & Disk_name & "','" & Disk_Frmt & "','" & Disk_Cmprssd1 & "'," & Disk_Size & "," & Disk_Free & "," & Disk_Used     

    'SQL = "insert into demo1(servername, cpu, loadpercentage, pagespersec, phymem, virtmem) select '" & Computer & "','" & cpuid & "', " & cpuload & "," & ppsec & "," & phymm & "," & virtmm

    adrec2.open SQL_DiskDtls,Adcn,2,3

    But I got the following error :

     Microsoft OLE DB Provider for SQL Server : Arithmetic overflow error converting numeric to data type int.

    Can someone tell me where and how I have gone wrong and help me rectify this please!!

     

     

     

     

     

  • Can you give me the table structure or just check every column datatype and values returned by your WSH variables .

    You can better implement this with a stored procedure.

    may be              Disk_Size = wbemDiskDtl.Size

                           dsk_Free = wbemDiskDtl.FreeSpace

                           d  isk_Used = Disk_Size - Disk_Free

     returning values greator than 2,147,483,647, if these column datatypes are int inside the database

     

  • Simply check the maximum value of all your different numeric attributes [wherever they originate from] and compare it to the BOL-section on datatype ranges. Your question is not really concise


    _/_/_/ paramind _/_/_/

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply