Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need some help with osql + sql

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,39315
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need some help with osql + sql
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Need some help with osql + sql - 10/31/2006 2:50:44 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi All,
I need some help regarding the following.
I am trying to run a script that will backup / restore a sql database using osql.exe util.
I have 2 scripts that manage to connect to the Database using the osql.exe but the next issue is that it has to send 2 -3 commands.
The part of the connection will give me:
1>

This means that the connection to the DB was made and now it is waiting for instructions.
The 2 scripts do the following.
The first scripts creates a txt file with the commands and when the connection is working it doesnt send them.

The second script i tried to use the sendkeys but this doesnt help.
I believe i am doing something wrong and i believe it is pretty easy for your VB gurus.

Here are the scripts

Script I

      



Script II

      


Thanks in advance

< Message edited by buffi -- 11/27/2006 6:56:24 PM >
 
 
Post #: 1
 
 RE: Need some help with osql + sql - 10/31/2006 4:29:46 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
Your first script wont work as is:
  • you have the instructions commented out
  • strinstructions is not a variable, strInstructions = ".\inst.txt" doesnt work, you have to read the file back in. just save it as a string variable
  • I am not sure about the .\ in front of osql, take that out and try again

so,
objShell.run ".\osql.exe -U admin -P admin -S 10.161.55.200" '& strInstructions, 1, True
would just give you a login prompt like you said.

I wouldnt even mess with sendkeys at all.

There are ways to connect to mssql without shelling out to osql, for example:

objConnection.open "Driver={SQL Server};Server=server;Database=DB;Uid=user;Pwd=password;"

query = "SELECT [column] FROM [db].[dbo].[table]"
objConnection.Execute query

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to buffi)
 
 
Post #: 2
 
 RE: Need some help with osql + sql - 11/1/2006 12:31:49 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi,
Thanks for the help.
I dont know how to work using the objConnection

Can you translate the osql.exe line to the objConnection?
I mean if my line is
osql.exe -U admin -P admin -S 10.161.55.200 --> this will create the connection to the db using the osql shell.

How do i write it in objConnection?
I hope i dont need the ODBC connection since i am trying to avoid crearting such a connection.
This script i am trying to do should be user friendly so i want less complication for the user.


Thanks in advance.
Buff

(in reply to kirrilian)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need some help with osql + sql Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts