Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Using ADO to connect to a database

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Using ADO to connect to a database
  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 >>
 Using ADO to connect to a database - 10/7/2008 1:04:39 AM   
  Alan

 

Posts: 1
Score: 0
Joined: 10/6/2008
Status: offline
Hi All

Can anyone help

I have Microsoft Server 2005 installed, and would like to use VB script to attach to a database and edit one of the tables in the database.

I believe that I can use the the ADODB object to do this but can't figure out how to use it, currently I'm stuck at establishing a connection.

The following is as far as I have got

Dim objConnection
Dim objRecordset
Dim strConnectionString

strConnectionString = "Provider=SQLOLEDB.1; Data Source=C:\963Projects\Backup\Fujitsu\TempDataBase\i96X_data.mdf"

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

objConnection.Open strConnectionString


The Error message I get is Object Required 'Server'

So I assume my connection string is incorrect can anyone help

 
 
Post #: 1
 
 RE: Using ADO to connect to a database - 10/8/2008 8:53:05 AM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Alan,

the error message indicates thatyou are using code like "Server.ThisOrThat" in the
code you didn't show.

Regards

ehvbs

(in reply to Alan)
 
 
Post #: 2
 
 RE: Using ADO to connect to a database - 10/9/2008 1:01:16 PM   
  fosterr_2000

 

Posts: 115
Score: 0
Joined: 12/18/2004
From:
Status: offline
When connecting to a SQL database you are connecting through the SQL services running on your database server not to the actual .mdf file.  Therefore the "Data Source=" should be the set to the server name not the path to the .mdf file.  You


strConnectionString = "Provider=SQLOLEDB.1; Data Source=C:\963Projects\Backup\Fujitsu\TempDataBase\i96X_data.mdf"

This should be more like:

strConnectionString = "Provider=SQLOLEDB;Data Source=SQLServer-01;" &_
"Initial Catalog= your_database_name;UserId=your_username;Password=your_password;"

where SQLServer-01 is the name of the SQL server that holds the database.  You also need to a username and a password or you could use Integrated Security.

Here is a page that may help with this:  http://www.webcheatsheet.com/ASP/sqlserver_connection_strings.php

If you are locked in to using the OLE DB methode then here is a sample using the ODBC method which I am much more familiar with:

Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Driver={SQL Server};" & _
                     "Server=SQLServer-01;" & _
                     "Database=DatabaseName;" & _
                     "Uid=your_username;" & _
                     "Pwd=your_password;"
  Set objRSSQL = CreateObject("ADODB.Recordset")
  strSQL = "Your sql statement goes here"
  objRSSQL.Open strSQL, objConnection 

Hope this helps.

(in reply to ehvbs)
 
 
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 >> Using ADO to connect to a database 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