Listing 3: GetDBData.vbs Option Explicit Dim sServer Dim sLogin Dim sPwd Dim oCn Dim oRs Dim sNames Dim oFso Dim oFileOut Dim sLineOut BEGIN CALLOUT A ' Set the database connection information sServer = "YourSQLServer" sLogin = "YourLogin" sPwd = "YourPassword" END CALLOUT A BEGIN CALLOUT B ' Create the ADO Connection and Recordset objects. Set oCn = CreateObject( "ADODB.Connection" ) Set oRs = CreateObject( "ADODB.Recordset" ) END CALLOUT B ' Create a FileSystemObject. Set oFso = CreateObject("Scripting.FileSystemObject") ' Set the conneciton string, open the connection and get rows. oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _ ";SERVER=" & sServer & _ ";UID=" & sLogin & _ ";PWD=" & sPwd & _ ";DATABASE=pubs" oCn.open oRs.Open "Select au_lname, au_fname from authors", oCn ' Create a file to hold the data. set oFileOut = oFso.CreateTextFile("DataFile.txt", True) ' Read through all the rows. Dim i While Not oRs.EOF ' Get the column data for each column in the row. For i = 0 to oRs.Fields.Count - 1 sLineOut = sLineOut & oRs.Fields(i).Value ' Separate the fields with commas If i < oRs.Fields.Count - 1 Then sLineOut = sLineOut & "," End If Next ' Write the line to the file. oFileOut.WriteLine(sLineOut) sLineOut = "" oRS.MoveNext Wend ' We're finished—close the database objects. oRs.Close oFileOut.Close