Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Changes not saving.

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Changes not saving.
  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 >>
 Changes not saving. - 5/9/2006 4:26:40 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
Hi.  I'm pulling stuff from the db using adodb.connection and populate them in a user account in active directory.  The data pulls fine but i can't get it to save the changes.
here's part of the code.  i left out stuff like variable declaration out.

Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
Set oIADSUser = GetObject("LDAP://OU=Users,OU=myou,"& strDefaultNC)

for each x in oIADSUser
    On Error Resume Next
    query = "select * from mytable"
    set result = sqlConn.execute(query)
    set user = x
    x.put "description", result("descriptionfield")
    x.put "telephoneNumber", result("phonefield")
   x.setinfo
            If Err.Number <> 0 Then
            wscript.echo "Error saving"
            wscript.quit
            end if
next
wscript.echo "finish"
wscript.quit
 
 
Post #: 1
 
 RE: Changes not saving. - 5/9/2006 8:02:43 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Do you need to move the record set to the first record before you try to access the data in it?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 2
 
 RE: Changes not saving. - 5/10/2006 5:34:29 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
actually, my query is like select * from mytable where id=1000
it should only return one record.

quote:

ORIGINAL: ebgreen

Do you need to move the record set to the first record before you try to access the data in it?

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Changes not saving. - 5/10/2006 7:49:41 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Still, did you try issueing a .MoveFirst command?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 4
 
 RE: Changes not saving. - 5/10/2006 8:10:19 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
Can you give me an example that pertains to my code?  Thanks.

quote:

ORIGINAL: ebgreen

Still, did you try issueing a .MoveFirst command?

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Changes not saving. - 5/10/2006 8:13:27 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
[Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
Set oIADSUser = GetObject("LDAP://OU=Users,OU=myou,"& strDefaultNC)

for each x in oIADSUser
    On Error Resume Next
    query = "select * from mytable"
    set result = sqlConn.execute(query)
  result.MoveFirst
    set user = x
    x.put "description", result("descriptionfield")
    x.put "telephoneNumber", result("phonefield")
   x.setinfo
            If Err.Number <> 0 Then
            wscript.echo "Error saving"
            wscript.quit
            end if
next
wscript.echo "finish"
wscript.quit

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 6
 
 RE: Changes not saving. - 5/10/2006 8:15:02 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
quote:

ORIGINAL: ebgreen

Still, did you try issueing a .MoveFirst command?


Please ebgreen - look at this code:


      

and its output:


      

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Changes not saving. - 5/10/2006 8:21:30 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
That is why I first said:

Do you need to move the record set to the first record before you try to access the data in it?

Apparently you don't need to. Next I would ask what purpose this line serves in the code:
set user = x

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Changes not saving. - 5/10/2006 8:38:06 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
oops.  i commented out set user=x.  Still not saving changes.



quote:

ORIGINAL: ebgreen

That is why I first said:

Do you need to move the record set to the first record before you try to access the data in it?

Apparently you don't need to. Next I would ask what purpose this line serves in the code:
set user = x

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Changes not saving. - 5/10/2006 9:07:39 AM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi cykill,

as I don't know about/use LDAP, this is pure Voodoo. But I'd try
something like this:

Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
Set oIADSUser = GetObject("LDAP://OU=Users,OU=myou,"& strDefaultNC)

for each x in oIADSUser
    query = "select * from mytable"
    set result = sqlConn.execute(query)

     ' this should break, if there is something fishy with your query
     WScript.Echo "result( 'descriptionfield' ).Value: |" + result("descriptionfield").Value + "|"

    ' activate, if next line works
    ' x.put "description", result("descriptionfield").Value

    ' this should break, if there is something fishy with your LDAP access
    x.put "telephoneNumber", "4711 12345"
    x.setinfo

next
wscript.echo "finish"
wscript.quit

as i said: not tested.

(in reply to cykill)
 
 
Post #: 10
 
 RE: Changes not saving. - 5/10/2006 10:17:25 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
its breaking here.  however, its doing the query though.
i did wscript.echo result("descriptionfield") and it comes back with the correct thing.


quote:

ORIGINAL: ehvbs


     ' this should break, if there is something fishy with your query
     WScript.Echo "result( 'descriptionfield' ).Value: |" + result("descriptionfield").Value + "|"



(in reply to ehvbs)
 
 
Post #: 11
 
 RE: Changes not saving. - 5/10/2006 4:02:05 PM   
  ehvbs

 

Posts: 2204
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi cykill,

(1) I can't wait till you tell me the error message for my evil line

(2) How about commenting out my line and checking the writing part by setting telephoneNumber to a constant?

(in reply to cykill)
 
 
Post #: 12
 
 RE: Changes not saving. - 5/15/2006 6:02:52 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
I actually got it to update.  However, it only updates once.  It updates the first time i run the script, but after that, any changes in the script will not update anymore.  any ideas?


quote:

ORIGINAL: ehvbs

Hi cykill,

(1) I can't wait till you tell me the error message for my evil line

(2) How about commenting out my line and checking the writing part by setting telephoneNumber to a constant?

(in reply to ehvbs)
 
 
Post #: 13
 
 RE: Changes not saving. - 5/15/2006 6:10:32 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Could you post the semi-working code?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 14
 
 RE: Changes not saving. - 5/15/2006 6:29:55 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
ok.  here it is.

Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
Set oIADSUser = GetObject("LDAP://OU=Users,OU=myou,"& strDefaultNC)

for each x in oIADSUser
On Error Resume Next
set rs = CreateObject("ADODB.recordset")

    On Error Resume Next
    query = "select descriptionfield, phonefield from mytable where id="+ x.sAMAccount
    set rs = sqlConn.execute(query)
    rs.Open query, sqlConn
   with x
        .put "description", rs("descriptionfield")
        .put "telephoneNumber", rs("phonefield")
       .setinfo
    end with
next
wscript.echo "finish"
wscript.quit

quote:

ORIGINAL: ebgreen

Could you post the semi-working code?

(in reply to ebgreen)
 
 
Post #: 15
 
 RE: Changes not saving. - 5/16/2006 1:58:04 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
Any errors if you take out the On Error Resume Next?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 16
 
 RE: Changes not saving. - 5/16/2006 3:48:51 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
nope.  no errors.  the script takes a while to run, which is good cause its going through all the user accounts.  but it doesn't do anything after the second time running it.  does the AD need to be refreshed or something?

quote:

ORIGINAL: ebgreen

Any errors if you take out the On Error Resume Next?

(in reply to ebgreen)
 
 
Post #: 17
 
 RE: Changes not saving. - 5/16/2006 4:34:03 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
You sure that is all of your code? I don't see where you instantiate sqlConn.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to cykill)
 
 
Post #: 18
 
 RE: Changes not saving. - 5/16/2006 4:41:52 AM   
  cykill

 

Posts: 48
Score: 0
Joined: 2/4/2006
Status: offline
When I run this, its pulling the correct stuff from the db cause i tried outputting it to the screen.

dim sqlConn, rs, query
set sqlConn = CreateObject("ADODB.connection")
sqlConn.Open "driver=SQL Server;server=cisco;uid=4321;password=1234;database=webpage;"

Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
Set oIADSUser = GetObject("LDAP://OU=Users,OU=myou,"& strDefaultNC)

for each x in oIADSUser
On Error Resume Next
set rs = CreateObject("ADODB.recordset")

    On Error Resume Next
    query = "select descriptionfield, phonefield from mytable where id="+ x.sAMAccount
    set rs = sqlConn.execute(query)
    rs.Open query, sqlConn
   with x
        .put "description", rs("descriptionfield")
        .put "telephoneNumber", rs("phonefield")
       .setinfo
    end with
next
wscript.echo "finish"
wscript.quit

quote:

ORIGINAL: ebgreen

You sure that is all of your code? I don't see where you instantiate sqlConn.

(in reply to ebgreen)
 
 
Post #: 19
 
 
 
  

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 >> Changes not saving. 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