Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


same code different problem

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> same code different problem
  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 >>
 same code different problem - 5/23/2001 2:57:51 AM   
  daydreamer

 

Posts: 19
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
I'm having a database problem now. I get a error message everytime my program opens up the database. Can anyone help?

here's the error message:
Line: 37 Char: 3
Error: Data source name not found and no default driver specified.



here's the code:

Option Explicit

' Database Variables
Dim objConn, ObjRS, strQuery
Dim strConnection
Dim strAddress, StrSubject

' Mail Variables
Dim cdoSession, inbox, messages, message, msgID, i, objMessage, objMessages, objFolder, objSession, objMessageFilter

Const adUseServer = 2
Const adOpenKeyset = 1
Const adCmdTable = 2
Const adLockOptimistic = 3

Set objSession = CreateObject("MAPI.Session")
objSession.logon
Set objFolder = objSession.Inbox
Set objMessages = objFolder.Messages
Set objMessageFilter= objMessages.Filter
'objMessageFilter.Or= True
'objMessageFilter.Subject="Remove"
'objMessageFilter.Subject="Registration"
Set objMessage=objMessages.GetFirst

If objMessage Is Nothing Then
MsgBox "Folder is Empty"
else
'loop through other messages
Do While Not objMessage Is Nothing

strAddress= objMessage.Sender
strSubject = objMessage.Subject

Set objConn = CreateObject("ADODB.Connection")
strConnection= "DSN=POCKETMOSAIC"
objConn.Open strConnection 'line 37
strQuery= "SELECT PagerAddress FROM Users "
strQuery= strQuery & "ORDER BY PagerAddress"

Set objRS = objConn.Execute ( strQuery )

'if the pager address needs to be removed from the db
if strSubject = "Remove" then
MsgBox "remove"
While not(objRS.EOF)
if objRS("PagerNumber") = strAddress Then
objRS.Delete
MsgBox strAddress
end if
wend

'if the pager address need to be added to the db
ElseIf StrSubject = "Registration" then
MsgBox "Add"
objRS.AddNew
objRS("PagerNumber")=strAddress

objRS.Update
MsgBox strAddress

End if
Set objMessage= objMessages.GetNext
Loop
End if
objRS.close
objConn.close

Set objMessage = nothing
Set objMessages = nothing
Set objFolder= nothing
Set objSession = nothing
Set objRS = nothing
set objConn= nothing
MsgBox "Done!"

cdoSession.Logoff
 
 
Post #: 1
 
 Re: same code different problem - 5/23/2001 3:01:57 AM   
  hennykoe

 

Posts: 9
Score: 0
Joined: 5/23/2001
From:
Status: offline
It appears that you did not use ODBC Data Sources in the Control Panel to define DSN=POCKETMOSAIC on the machine on which the code is running.

(in reply to daydreamer)
 
 
Post #: 2
 
 Re: same code different problem - 5/23/2001 3:03:58 AM   
  daydreamer

 

Posts: 19
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
Thanks but now it doesn't open the record set.

Here's the error:
line 57
error: wrong number of arguements or invalid property assignment: "open"

Here's my updated code:

Option Explicit

' Database Variables
Dim objConn, ObjRS, strQuery
Dim strConnection
Dim strAddress, StrSubject

' Mail Variables
Dim cdoSession, inbox, messages, message, msgID, i, objMessage, objMessages, objFolder, objSession, objMessageFilter

Const adUseServer = 2
Const adOpenKeyset = 1
Const adCmdTable = 2
Const adLockOptimistic = 3

Set objSession = CreateObject("MAPI.Session")
objSession.logon
Set objFolder = objSession.Inbox
Set objMessages = objFolder.Messages
Set objMessageFilter= objMessages.Filter
'objMessageFilter.Or= True
'objMessageFilter.Subject="Remove"
'objMessageFilter.Subject="Registration"
Set objMessage=objMessages.GetFirst

If objMessage Is Nothing Then
MsgBox "Folder is Empty"
else
'loop through other messages
Do While Not objMessage Is Nothing

strAddress= objMessage.Sender
strSubject = objMessage.Subject

Set objConn = CreateObject("ADODB.Connection")
strConnection= "DSN=POCKETMOSAIC"
objConn.Open strConnection
strQuery= "SELECT PagerAddress FROM Users "
strQuery= strQuery & "ORDER BY PagerAddress"

'if the pager address needs to be removed from the db
if strSubject = "Remove" then
MsgBox "remove"
Set objRS = objConn.Execute ( strQuery )
While not(objRS.EOF)
if objRS("PagerNumber") = strAddress Then
objRS.Delete
MsgBox strAddress
end if
wend

'if the pager address need to be added to the db
ElseIf StrSubject = "Registration" then
MsgBox "Add"
set objRS = createobject("ADODB.Connection")
objRS.CursorLocation = adUseServer
objRS.Open "Users", objConn, adOpenKeyset, adLockOptimistic, adCmdTable

objRS.AddNew
objRS("PagerNumber")=strAddress

objRS.Update
MsgBox strAddress

End if
Set objMessage= objMessages.GetNext
Loop
End if
objRS.close
objConn.close

Set objMessage = nothing
Set objMessages = nothing
Set objFolder= nothing
Set objSession = nothing
Set objRS = nothing
set objConn= nothing
MsgBox "Done!"

cdoSession.Logoff


I hate always asking for help, but I'm new to the database stuff...

(in reply to daydreamer)
 
 
Post #: 3
 
 Re: same code different problem - 5/23/2001 3:07:04 AM   
  mstargas

 

Posts: 6
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
objRS.Open "Users", objConn, adOpenKeyset, adLockOptimistic, adCmdTable

I assume is line 57???

"Users" is not a valid SQL Statement --

If you wish to retrieve all records from your Users table, then ask:

"SELECT * FROM Users"

or as you put before,

"SELECT PagerAddress FROM Users"

(in reply to daydreamer)
 
 
Post #: 4
 
 Re: same code different problem - 5/23/2001 3:09:08 AM   
  pedx

 

Posts: 16
Score: 0
Joined: 5/22/2001
From: USA
Status: offline
Do some more research. You never CLOSED objRS before reusing it and from what I see in MSDN, objRS.Open takes 0 parameters.

open Method

Opens a Recordset object.

Syntax

object.open()

Parameters

object

A script object.

Remarks

Use the setRecordSource method to set the connection properties before opening a Recordset object. Use the isOpen method to determine if a Recordset object is open.

Example

This shows how to change the where clause of a query, by using a value from a Textbox.

function btnQuery_onclick()
{
if ( RS1.isOpen() )
RS1.close(); // must close the recordset before changing the SQLText
RS1.setSQLText('Select * from TABLE1 where (ID =' + txtQuery.value + ')');
RS1.open();
}

(in reply to daydreamer)
 
 
Post #: 5
 
 Re: same code different problem - 5/23/2001 3:11:10 AM   
  pagooda

 

Posts: 54
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
actually, the .open method can take up to 5 parameters -- and even more if the fifth has several options OR'd together...

ie...

rs.open sqlStatement, conObject, cursorType, lockType, options


--

(in reply to daydreamer)
 
 
Post #: 6
 
 Re: same code different problem - 5/23/2001 3:13:38 AM   
  daydreamer

 

Posts: 19
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
I found my problem...

i put this:

set objRS = createobject("ADODB.Connection")

instead of this

set objRS = createobject("ADODB.recordset")

Thanks for all the help

(in reply to daydreamer)
 
 
Post #: 7
 
 
 
  

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 >> same code different problem 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