Login | |
|
 |
mysql script! - 5/3/2007 2:05:00 AM
|
|
 |
|
| |
jtrinidadmap
Posts: 6
Score: 0
Joined: 5/3/2007
Status: offline
|
Original message moved by dm_4ever Reason : Moving To Appropriate Forum hi, im newbi in vbscript, i need help, i try to do a script that makes 2 conections, first, with one server to get the printer that are installed there, on this server, 2n u have to make another conection in my sql server to put the info of the printers in a table, i already have the code for make the conections and the code for get the info of the printers, now when i run the script and check my database, the table is empty, somebody can help me? thanks!!
|
|
| |
|
|
|
 |
RE: mysql script! - 5/3/2007 2:51:09 AM
|
|
 |
|
| |
jtrinidadmap
Posts: 6
Score: 0
Joined: 5/3/2007
Status: offline
|
On Error Resume Next Dim strComputer, k, objGroup, objShell Dim objWMIService, colItems, ErrState, strPorts, strPortNum dim consulta, cnn Set objShell = CreateObject("WScript.Shell") 'Value assignment Set objShell = CreateObject("WScript.Shell") ''Sheet = spreadsheet page, k = row in sheet Sheet = 1 k = 2 strComputer = InputBox ("Please type the print server name to check, " & vbCrLf & _ "Else enter ALL for all CC print servers", "Server Name","CCPS01") if strComputer = "" then ' WScript.quit 'end if ''Change this to fit your server situation Select Case UCase(strComputer) Case "ALL" PrintServer("CCPS01") Sheet = Sheet + 1 PrintServer("PS02") Sheet = Sheet + 1 PrintServer("PS03") Case Else PrintServer(strComputer) End Select Function PrintServer(strComputer) k=2 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48) Set colPorts = objWMIService.ExecQuery("Select * from Win32_TCPIPPrinterPort") Set strPorts = CreateObject("Scripting.Dictionary") Set strPortNum = CreateObject("Scripting.Dictionary") For Each objPort in colPorts strPorts.add objPort.Name, objPort.HostAddress strPortNum.add objPort.Name, objPort.PortNumber Next end function 'para la conexion con mysql Private Sub Form_Load() Set cnn = New ADODB.Connection cnn.ConnectionString ="Driver={MySQL ODBC 3.51 Driver};Server=servername;Port=3306;Database=dbname;User=user;Password=password;Option=3;" cnn.Open Set rec = New ADODB.Recordset rec.Open "SELECT * FROM ""TABLE""" , cnn, adOpenDynamic, adOpenDynamic rec.MoveFirst Do While Not rec.EOF MsgBox rec.Fields("Cuenta").Value rec.MoveNext Set command = New ADODB.Command command.ActiveConnection=cnn LOAD DATA INFILE "C:File.xls" INTO TABLE consulta = "insert into tabla (Nom_Impresora,IP,Marca_Modelo,Depto,Ubicacion_Logica,Status,Ubicacion_Fisica) values("& objItem.Name &","strPorts.Item","objItem.DriverName","objItem.Comment","","objItem.Status","objItem.Location")" command.text=consulta command.execute Loop cnn.close 'Next End Sub 'WScript.quit end if WScript.Echo "Printer listing is done" Wscript.quit
|
|
| |
|
|
|
 |
RE: mysql script! - 5/3/2007 7:53:34 AM
|
|
 |
|
| |
ehvbs
Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
|
Hi jtrinidadmap, Because I can't test drive your script, all I can say is: (1) get rid of the global "On Error Resume Next" and see what the error messages tell you (2) Check rec.Open "SELECT * FROM ""TABLE""" , cnn, adOpenDynamic, adOpenDynamic (3) Try Set command.ActiveConnection=cnn (4) Is there a Comment ' missing LOAD DATA INFILE "C:File.xls" INTO TABLE (5) This looks fishy to me: consulta = "insert into tabla (Nom_Impresora,IP,Marca_Modelo,Depto,Ubicacion_Logica,Status,Ubicacion_Fisica) values("& objItem.Name &","strPorts.Item","objItem.DriverName","objItem.Comment","","objItem.Status","objItem.Location")" I would expect something like: consulta = "insert into tabla (Nom_I, ... ) values( '" & oItem.Name & "', '" ... ) " String Values should be enclosed in single quotes. Sorry I'm not able to give better advice. Good luck! ehvbs
|
|
| |
|
|
|
 |
RE: mysql script! - 5/7/2007 3:01:21 AM
|
|
 |
|
| |
jtrinidadmap
Posts: 6
Score: 0
Joined: 5/3/2007
Status: offline
|
thanks i try that but when the scripts un, display a error message, says: "Error in line 72 char 11" Expected end statement" and the line 72 is (in bold) LOAD DATA INFILE "C:Printers_ejercito_root.xls" INTO IMPRESORAS consulta = "insert into tabla (Nom_Impresora,IP,Marca_Modelo,Depto,Ubicacion_Logica,Status,Ubicacion_Fisica) values('& objItem.Name &','strPorts.Item','objItem.DriverName','objItem.Comment',' ','objItem.Status','objItem.Location')" command.text=consulta command.execute Loop cnn.close Next End Sub 'WScript.quit end if WScript.Echo "Printer listing is done" Wscript.quit and i check and the file exists i'll been thankful if anyone help me thanks!!
|
|
| |
|
|
|
 |
RE: mysql script! - 5/8/2007 1:50:42 AM
|
|
 |
|
| |
jtrinidadmap
Posts: 6
Score: 0
Joined: 5/3/2007
Status: offline
|
HI, i make the changes you recommend but the scripts dosnt makes anything. this is my code looks like 'On Error Resume Next Dim strComputer, k, objGroup, objShell Dim objWMIService, colItems, ErrState, strPorts, strPortNum dim consulta, cnn Set objShell = CreateObject("WScript.Shell") 'Value assignment Set objShell = CreateObject("WScript.Shell") ''Sheet = spreadsheet page, k = row in sheet Sheet = 1 k = 2 strComputer = InputBox ("Please type the print server name to check, " & vbCrLf & _ "Else enter ALL for all CC print servers", "Server Name","CCPS01") if strComputer = "" then ' WScript.quit 'end if ''Change this to fit your server situation Select Case UCase(strComputer) Case "ALL" PrintServer("CCPS01") Sheet = Sheet + 1 PrintServer("PS02") Sheet = Sheet + 1 PrintServer("PS03") Case Else PrintServer(strComputer) End Select WScript.Echo "Conectando con el Print Server..." Function PrintServer(strComputer) k=2 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48) Set colPorts = objWMIService.ExecQuery("Select * from Win32_TCPIPPrinterPort") Set strPorts = CreateObject("Scripting.Dictionary") Set strPortNum = CreateObject("Scripting.Dictionary") For Each objPort in colPorts strPorts.add objPort.Name, objPort.HostAddress strPortNum.add objPort.Name, objPort.PortNumber Next end function WScript.Echo "Conectando con el servidor MYSQL..." 'para la conexion con mysql ' Private Sub Form_Load() Sub Form_Load() Set cnn = New ADODB.Connection cnn.ConnectionString ="Driver={MySQL ODBC 3.51 Driver};Server=Servername;Port=3306;Database=dbname;User=usr;Password=pass;Option=3;" cnn.Open Set rec = New ADODB.Recordset rec.Open "SELECT * FROM ""TABLE""" , cnn, adOpenDynamic rec.MoveFirst Do While Not rec.EOF MsgBox rec.Fields("Cuenta").Value rec.MoveNext Set command = New ADODB.Command Set command.ActiveConnection=cnn WScript.Echo "Insertando Datos..." 'LOAD DATA INFILE "C:Printers_ejercito_root.xls" INTO IMPRESORAS consulta = "insert into IMPRESORAS(Nom_Impresora,IP,Marca_Modelo,Depto,Ubicacion_Logica,Status,Ubicacion_Fisica) values(""&objItem.Name&"",""&strPorts.Item&"",""&objItem.DriverName&"",""&objItem.Comment&"","",""&objItem.Status&"",""&objItem.Location&"")" command.text=consulta command.execute Loop cnn.close 'Next End Sub 'WScript.quit end if WScript.Echo "Printer listing is done" Wscript.quit i put echo sentences for know if the script do some activities and didnt display anything, only the last echoe, i didnt know why! can anybody help me? thanks, i revie the table and the script dosnt insert anything, i think its because it dosnt bring any data from the print server. thanks!
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|