Results 1 to 12 of 12

Thread: [RESOLVED] vbs: Connect SQL Server

  1. #1
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Resolved [RESOLVED] vbs: Connect SQL Server

    Error on highlighted line: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one other
    Code:
    iconnTrans = CreateObject("ADODB.Connection")
    Set iconnPromo = CreateObject("ADODB.Connection")
    
    Set rsTrans = CreateObject("ADODB.Recordset")
    Set rsPromoTrans = CreateObject("ADODB.Recordset")
    
    iconnTrans.open _
    	"Provider=SQLOLEDB.1;Data Source = localhost\sqlexpress;Integrated Security = SSPI;Initial Catalog=dw2"
    
    iconnPromo.open _
    	"Provider=SQLOLEDB.1;Data Source = localhost\sqlexpress;Integrated Security = SSPI;Initial Catalog=dw"
    
    rsTrans.open "SELECT TransactionID, StockID, Promotion FROM Transactions WHERE OnPromotion='yes'", iconnTrans, adOpenStatic, adLockOptimistic 
    
    Do Until rsTrans.EOF 
    	
    	wscript.echo rstrans.TransactionID
            rsTrans.Movenext
    Loop
    If I modify my recordset string to
    Code:
    sTrans.open "SELECT TransactionID, StockID, Promotion FROM Transactions WHERE OnPromotion='yes'", iconnTrans
    No records are being returned. rsTrans.RecordCount=-1
    Mel

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: vbs: Connect SQL Server

    In terms of the error, did you declare the constants? (on that line, they are adOpenStatic and adLockOptimistic)

    Regarding .RecordCount=-1 , that does not mean that there are no records - it means that the exact amount of records is currently unknown (and there is probably at least one record). .EOF and .BOF will still work as expected.

  3. #3
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Hi Si,
    Thanks for the reply. I don't get your question? What constants need to be declared?
    Also, how do I determine the recordcount? When I run the code without adOpenStatic and adLockOptimistic I get an error at line wscript.echo rstrans.TransactionID Error: Object does't support this property or method: 'rsTrans.transactionID'
    Mel

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: vbs: Connect SQL Server

    Quote Originally Posted by mel_flynn View Post
    Hi Si,
    Thanks for the reply. I don't get your question? What constants need to be declared?
    adOpenStatic and adLockOptimistic

    If you use VB6 (or similar), when you add a Reference, the constants are included... in VBScript you need to declare them yourself. You can use the Object Browser in VB6 etc to find out what the declarations should be.
    Also, how do I determine the recordcount?
    Do you need to?

    For the kind of code you showed, there is absolutely no reason to know it.
    When I run the code without adOpenStatic and adLockOptimistic I get an error at line wscript.echo rstrans.TransactionID Error: Object does't support this property or method: 'rsTrans.transactionID'
    That is to be expected, because that is not the syntax to refer to a field.

    As with VB6 etc, a valid way is: rstrans.Fields("TransactionID").Value

  5. #5
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Thanks a mill Si. Do I need adOpenStatic and adLockOptimistic? I need to update the recordset.
    Mel

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: vbs: Connect SQL Server

    You need to use something other than the defaults, but perhaps not those specific ones.

    For more information, see the article What do the parameters of the recordset.Open method mean? from our Database Development FAQs/Tutorials (at the top of the Database Development forum)

  7. #7
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Thanks Si.
    Mel

  8. #8
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Still an error on highlighted line: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one other
    Code:
    Set iconnTrans = CreateObject("ADODB.Connection")
    
    iconnTrans.open _
    	"Provider=SQLOLEDB.1;Data Source = localhost\sqlexpress;Integrated Security = SSPI;Initial Catalog=dw2"
    
    Set rsTrans = CreateObject("ADODB.Recordset")
    Set rsTrans.ActiveConnection=iconnTrans
    rsTrans.CursorLocation = adUseClient
    rsTrans.CursorType = adOpenDynamic
    rsTrans.open "SELECT TransactionID, StockID, Promotion FROM Transactions WHERE OnPromotion='yes'"
    Mel

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: vbs: Connect SQL Server

    Have you declared adUseClient and adOpenDynamic? (you need to)

  10. #10
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Yes
    Code:
    dim adUseClient
    dim adOpenDynamic
    
    Set iconnTrans = CreateObject("ADODB.Connection")
    
    iconnTrans.open _
    	"Provider=SQLOLEDB.1;Data Source = localhost\sqlexpress;Integrated Security = SSPI;Initial Catalog=dw2"
    
    Set rsTrans = CreateObject("ADODB.Recordset")
    Set rsTrans.ActiveConnection=iconnTrans
    rsTrans.CursorLocation = adUseClient
    rsTrans.CursorType = adOpenDynamic
    rsTrans.open "SELECT TransactionID, StockID, Promotion FROM Transactions WHERE OnPromotion='yes'"
    Mel

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,548

    Re: vbs: Connect SQL Server

    Actually no.

    You have declared variables, and not assigned them a value.

    They are supposed to be constants with particular values, which you can find using the method I described above (or a web search, etc).

  12. #12
    Frenzied Member
    Join Date
    Nov 01
    Posts
    1,368

    Re: vbs: Connect SQL Server

    Thanks a mill for your help.
    Code:
    Const adLockBatchOptimistic = 4
    Const adUseClient = 3 
    
    Set iconnTrans = CreateObject("ADODB.Connection")
    
    iconnTrans.open _
    	"Provider=SQLOLEDB.1;Data Source = localhost\sqlexpress;Integrated Security = SSPI;Initial Catalog=dw2"
    
    Set rsTrans = CreateObject("ADODB.Recordset")
    
    rsTrans.CursorLocation = adUseClient
    rsTrans.LockType = adLockBatchOptimistic
    rsTrans.open "SELECT * FROM ir_Transactions", iconnTrans
    Mel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •