Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


vbscript connection to sql server database

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbscript connection to sql server 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 >>
 vbscript connection to sql server database - 3/10/2005 7:03:17 AM   
  ny3ranger

 

Posts: 2
Score: 0
Joined: 3/10/2005
From:
Status: offline
Is there any way to connect to a sql server 7 or 8 database.

My whole task is to create a script that will update user profiles in Active Directory. Now a universal update to the active directory is not that difficlut. But for testing I am trying to write a script that will just do the person that runs the script (yes the people that will run the script in this state all have admin rights). But my problem comes because I cant get the users full name (that is the way the cn object in out active directory can be accessed, unless there is another way to access the user object with the logon that would be great but as it stands I can use the Last, First to make the LDAP connection). Therefore I was thinking that I can connect to our database that has the login with their full name and then use that full name to connect to ldap and make the .profilePath change. Does anyone know how to connect to Ad with login??? If not can you give me an example on how to query a database in sqlserver 7.0 and then I'm good to go.

Thanks,
Tash
 
 
Post #: 1
 
 Re: vbscript connection to sql server database - 3/10/2005 7:56:41 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Let me clearify it just a bit, you want to bind to the user object based on the logon name ?

(in reply to ny3ranger)
 
 
Post #: 2
 
 Re: vbscript connection to sql server database - 3/10/2005 8:27:55 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
The following script will bind to a user object based on the supplied user logon name and displays the assocaited profile path which should be enough to get you started.

Make appropriate changes to the pat and domain variables to reflect the actual values used.

============================================================================================
Option Explicit
Dim conn, cmd, rs, user, pat, domain

domain = "dc=ca,dc=pm,dc=com"
pat = "userID"

Set conn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
conn.provider = "adsdsoobject"
conn.open "active directory provider"
cmd.activeconnection = conn
cmd.commandtext = "<LDAP://" & domain & ">;(samaccountname=" & pat & ");distinguishedname;subtree"
Set rs = cmd.Execute
If rs.eof Then
WScript.Echo "No user userID matched """ & pat & """ is found."
Else
Set user = GetObject("LDAP://" & rs("distinguishedname"))
WScript.Echo user.Get("profilepath")
End If

(in reply to ny3ranger)
 
 
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 >> vbscript connection to sql server 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