Jump to content

Access SQL Server


Nick
 Share


Go to solution Solved by Tom Wellige,

Recommended Posts

I'm trying to access the SwyxCallDetails table on our SQL Server.

The connection does work but the query at the end doesn't and I don't know why.

 

I'm positive that I've missed something but u don't know what. 

 

The End Goal is to get the DB entry for the correspondent CakllID into the "Query" Variable 

 

Function EMAIL(CalledID)

    PBXScript.OutputTrace "--------->EMAIL() Called"

    Dim Connection
    Set Connection = CreateObject("ADODB.Connection")
    

    Dim ConString 
    ConString = "Provider=SQLOLEDB;Server=##;database=SwyxCallDetails;User ID=IpPbxCDR_User;Password=##"

    PBXScript.OutputTrace "----------->" & ConString

    Connection.Open ConString


    if Connection.State = 1 Then
        PBXScript.OutputTrace "-------->Connected"
    Else
        PBXScript.OutputTrace "-------->Not Connected"
    End if


    Dim SqlString
    SqlString = "SELECT CalledNumber FROM dbo.IpPbxCDR WHERE CallId = '" & CallId & "'"

    PBXScript.OutputTrace "--------->" & SqlString


    Dim Query 
    Query = CreateObject("ADODB.Recordset")
    PBXScript.OutputTrace "---------> Query object created"
    Query.Open SqlString, Connection
    PBXScript.OutputTrace "--------> Query Connected"


    EMAIL = Query

    Query.Close
    Connection.Close

End Function

 

Link to comment
Share on other sites


  • Solution

There is a "Set" missig in front of

 

Query = CreateObject("ADODB.Recordset")

 

Also, please take a look into the CheckCallerInDatabase example from the Function Collection to see how you can do error tracing and error handling.

 

When dealing with external data sources (e.g. files or databases) this is sort of mandatory.

 

 

Your function returns at the end a closed recordset which you will not be able to access anymore. You should do all the needed data handling within your function, so you will be able to close the recordset in the end properly without anything else fails afterwards because of this.

 

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.