Walser
Fri Dec 07 04:08:57 PST 2007
hello
it runs perfectly!
thank you
"ekkehard.horner" <ekkehard.horner@arcor.de> schrieb im Newsbeitrag
news:4758feab$0$16661$9b4e6d93@newsspool3.arcor-online.net...
> Walser Mark schrieb:
>> hello ng
>>
>> how can I access to sql server with scripting host?
>> I want read some user records and after write into the Active Directory.
>>
>> Thanks in advance for your help
>>
>> mark
>>
> This very simple example
>
> ' for more elaborate connections strings see
> '
http://www.connectionstrings.com/?carrier=sqlserver
> Dim sSrv : sSrv = "w2k"
> Dim sDB : sDB = "pubs"
> Dim sCS1 : sCS1 = Join( Array( _
> "Driver={SQL Server}" _
> , "Server=" & sSrv _
> , "Database=" & sDB _
> , "Trusted_Connection=Yes" _
> ), ";" )
>
> Dim oCN : Set oCN = CreateObject( "ADODB.Connection" )
> ' for more elaborate operations see ado<NN>.chm
> oCN.Open sCS1
>
> Dim sSQL : sSQL = "SELECT au_id, au_lname, au_fname FROM authors"
> Dim oRS : Set oRS = oCN.Execute( sSQL )
> showRS oRS
> oRS.Close
>
> oCN.Close
>
> Sub showRS( oRS )
> Const adClipString = 2 ' to keep ADO happy
> Dim sHead : sHead = ""
> Dim oFld
> For Each oFld In oRS.Fields
> sHead = sHead & vbTab & oFld.Name
> Next
> WScript.Echo Join( Array( _
> String( 70, "=" ) _
> , vbCrLf _
> , oRS.Source _
> , vbCrLf _
> , Mid( sHead, 2 ) _
> , vbCrLf _
> , String( 70, "-" ) _
> , vbCrLf _
> , oRS.GetString( adClipString, , vbTab, vbCrLf, "NULL" ) _
> , String( 70, "=" ) _
> ), "" )
> End Sub
>
> output:
>
> === cnctMSSQL: connect to MS SQLServer ============
> ===================================================
> SELECT au_id, au_lname, au_fname FROM authors
> au_id au_lname au_fname
> ---------------------------------------------------
> 409-56-7008 Bennet Abraham
> 648-92-1872 Blotchet-Halls Reginald
> 238-95-7766 Carson Cheryl
> 722-51-5454 DeFrance Michel
> 712-45-1867 del Castillo Innes
> 427-17-2319 Dull Ann
> 213-46-8915 Green Marjorie
> 527-72-3246 Greene Morningstar
> 472-27-2349 Gringlesby Burt
> 846-92-7186 Hunter Sheryl
> 756-30-7391 Karsen Livia
> 486-29-1786 Locksley Charlene
> 724-80-9391 MacFeather Stearns
> 893-72-1158 McBadden Heather
> 267-41-2394 O'Leary Michael
> 807-91-6654 Panteley Sylvia
> 998-72-3567 Ringer Albert
> 899-46-2035 Ringer Anne
> 341-22-1782 Smith Meander
> 274-80-9391 Straight Dean
> 724-08-9931 Stringer Dirk
> 172-32-1176 White Johnson
> 672-71-3249 Yokomoto Akiko
> ===================================================
> === cnctMSSQL: 0 done (00:00:00) ==================
>
> should get you started.
>