Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 VBSCRIPT for executing SQL Satements

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-09-27 : 09:12:29
Tapan writes "Can I access a SQL 2000 database from within my vbscripts. My need are simple select , insert , update and delete on an existing database.Can you pl. lead me to some examples?
Thanks in advance."

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-09-27 : 10:23:05
Here is an example of some code that I wrote for this purpose.
I call a stored proc which extracts some stored proc code by looking at the syscomments table.

[CODE]
Dim cn
Dim rs
Dim INFSO
Dim OU1
Dim PrevName
Dim WriteStr

SET INFSO = CreateObject("Scripting.FileSystemObject")
SET OU1 = INFSO.CreateTextFile("\\netapp2\shares\it\infocentre\users\duane\stuff\spextract.txt")


PrevName = ""
WriteStr = ""

Set cn = CreateObject("ADODB.Connection")
cn.CommandTimeout = 900
cn.ConnectionTimeout = 900
cn.Provider = "sqloledb"
cn.Open "Server=MyServer;Trusted_Connection=Yes;Database=MyDB"
Set rs = CreateObject("ADODB.Recordset")

rs.Open "exec getspcode", cn
Do While Not rs.EOF
If PrevName <> rs(0) Then
If WriteStr <> "" Then
ou1.Write(vbNewLine & vbnewline & "--------------------------------------------------------------------------------------" & VBNewLine & WriteStr)
End If
WriteStr = rs(3)
PrevName = rs(0)
Else
WriteStr = Writestr & rs(3)
End If
rs.MoveNext
Loop

If WriteStr <> "" Then
ou1.Write(vbNewLine & vbnewline & "--------------------------------------------------------------------------------------" & vbNewLine & WriteStr)
End If

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
ou1.Close
Set ou1 = Nothing
Set INFSO = Nothing
msgbox "Done"
[/CODE]

Duane.
Go to Top of Page
   

- Advertisement -