473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VBScript-Unable to get connected to database

BezerkRogue
I have created a script that automates the launching of an application based upon a value in the registry. For some reason, it is not connecting to the database to read what application it's supposed to launch. I have combed over this script and can't figure out what the issue is. Please help.

Expand|Select|Wrap|Line Numbers
  1.  
  2. ' VBScript File for synchronizing error proofing applications and launching the correct EP application on station start up.
  3.  
  4. 'Error handling
  5. On error resume next
  6.  
  7. 'Create variables
  8.  
  9. Dim objShell 'WScript Shell object
  10. Dim strReg1  'StationName
  11. Dim objConn  'Database Connection
  12. Dim strSQL   'SQL Command String
  13. Dim objRec   'Recordset
  14. Dim strConn  'Connection String
  15. Dim strEPApp 'Error Proofing Application String
  16. Dim appExec  'SyncToy executable variable
  17. Dim appExec2 'EP executable variable
  18.  
  19. 'Decalare and open connection string and recordset and set objects
  20. Set objConn = CreateObject("ADODB.Connection")
  21. strConn="Provider=SQLOLEDB; Data Source=XXXXXX;Trusted_Connection=Yes;Database=XXX;UID=XXX; PWD=XXX;"
  22.  
  23. Set objRec = CreateObject("ADODB.Recordset")
  24. Set objShell = WScript.CreateObject("Wscript.Shell")
  25.  
  26. 'Declare File and Reg variables
  27.  
  28. strReg1 = "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Error Proofing Station\Properties\StationName"
  29.  
  30. 'Declare variable for database records by reading registry values into recordset.
  31. Dim rec1
  32.  
  33. rec1 = objShell.RegRead(strReg1)
  34.  
  35. If rec1 = "" then
  36.     strReg1 = "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Prepick Error Proofing Station\Properties\StationName"
  37.     rec1 = objShell.RegRead(strReg1)
  38. End If
  39. wscript.echo rec1
  40.  
  41. 'Declare SQL Statements
  42. strSQL = "Select * from EPApps where StaName ='" & rec1 &"'"
  43. wscript.echo strSQL
  44. objRec.Open strSQL, strConn
  45. strEPApp = objRec.fields(2).value
  46.  
  47. 'Launch Synctoy App
  48. Dim WShell
  49. Set WShell = WScript.CreateObject("WScript.Shell")
  50. Set appExec = WShell.Exec("C:\SyncToy\SyncToy.exe -R")
  51. Wscript.Sleep 5000
  52. Set appExec2 = WShell.Exec("C:\Program Files\OnlineErrorProofing\" & strEPApp )
  53.  
At this point any help would be appreciated.

Thanks
Jul 14 '08 #1
1 1637
jeffstl
432 Expert 256MB
You have to open the connection to your database before you execute SQL on it.

Expand|Select|Wrap|Line Numbers
  1. 'Declare SQL Statements
  2. objConn.Open strConn
  3.  
  4. strSQL = "Select * from EPApps where StaName ='" & rec1 &"'"
  5. wscript.echo strSQL
  6. objRec.Open strSQL, strConn
  7. strEPApp = objRec.fields(2).value
  8.  
  9. objConn.Close
  10.  
  11.  
  12.  
I also notice you don't specify the path within the object so your going ot need to do something like this
Jul 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
29
by: Christopher Brandsdal | last post by:
If I have a .ASP page that runs JScript code - is it possible to include an ..ASP page that runs VBscript???
20
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
16
by: Mike Schinkel | last post by:
Does anyone know if there are bugs in VBScript's GetRef()? I'm using VBScript Version 5.6.8515 on Win2003Server w/ASP. Sometimes it returns an object that VarType() says is a vbObject. Other...
5
by: gpence | last post by:
!!! Newbie question warning !!! I am somewhat familiar with javascript's ability to "access" the browser's favorites list -- for example, using window.home() will take you to the default URL --...
2
by: Frank | last post by:
Can I do this? I add a session var in C# and ultimatly want to pass it into a vbscript client side activeX control. This is what I have so far but get " Object Required:'name2' " error. Can...
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
10
by: Shadow Lynx | last post by:
That subject packs a whallop, so let me explain in better detail what's happening and how it relates to ASPX pages... In a nutshell, if the first <script /on a page is of type "text/vbscript",...
6
by: rishabhshrivastava | last post by:
Hello All, I am using ASP.NET 2.0 and I am experiencing a problem using vbscript that is this script on client side is preventing the postback of my controls. I have a dropdownlist which is...
1
by: Andrew Wan | last post by:
How can VBScript code access JScript code variables in the same ASP page? <SCRIPT LANGAUGE="VBScript"> Dim a a = 10 </SCRIPT> <SCRIPT LANGUAGE="JScript"> Response.Write(a); </SCRIPT>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.