Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 6th, 2005, 12:27 PM
vc1 vc1 is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing sql server database trough vbs file

Can anyone please send me some sample code for accessing sqlserver database through a vbs file.

Thanks,
vineet


Reply With Quote
  #2 (permalink)  
Old February 6th, 2005, 01:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

Take a look at ISQL (http://msdn.microsoft.com/library/de..._isql_8r39.asp) I've used it on several projects to do the same thing.
Reply With Quote
  #3 (permalink)  
Old February 7th, 2005, 02:33 PM
vc1 vc1 is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please send me some sample code which is easy to understand as I am new to this technology.

Thanks for your help.

Reply With Quote
  #4 (permalink)  
Old February 14th, 2005, 09:13 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

What do you mean by "accessing" a SQL server? What do you want to do there?

Do you want to use a DSN, or ADO?

I use these connections to write data to SQL server. This may get you started if that is what you need:

'==========
strUserName = "yourSQLusername"
strPassword = "yourSQLpassword"
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=YourDSNName;", strUserName, strPassword
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM tblYourTable" , objConnection, adOpenStatic, adLockOptimistic

   objRecordset.AddNew
   objRecordset("Field1") = "YourData1"
   objRecordset("Field2") = "YourData2"
   '...
   objRecordset("Fieldn") = "YourDatan"
   objRecordset.Update

objRecordset.Close
objConnection.Close
'==========

HTH

mmcdonal
Reply With Quote
  #5 (permalink)  
Old February 14th, 2005, 09:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

BTW, this adds one new record to "tblYourTable" in a SQL server named "YourDSNName."

mmcdonal
Reply With Quote
  #6 (permalink)  
Old February 14th, 2005, 09:16 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, with an account name of "yourSQLusername" with write access to tblYourTable", using SQL login, and a password of "yourSQLpassword."


mmcdonal
Reply With Quote
  #7 (permalink)  
Old February 18th, 2005, 09:54 AM
vc1 vc1 is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,By accessing SQL server I mean querying the database or doing some inserts and updates.

Your code helped me.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert text file in sql server database sharvari_mothe Java Databases 3 June 5th, 2007 07:25 AM
how to store file in sql server 2000 database vivekkumar_23 SQL Server 2000 1 February 27th, 2006 10:41 PM
Upload a file to sql server database thas123 ASP.NET 1.0 and 1.1 Professional 3 January 9th, 2006 12:29 AM
Searching trough a database toni_montana PHP How-To 2 September 25th, 2004 09:17 AM
Emailing File from SQL Server Database hugh@kmcnetwork.com VB How-To 0 July 24th, 2004 09:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.