Download SMS Messaging Server    |     Visit the SMS Messaging Server website

Index - Log in! - Sign up! - Visit website
SQL Connection
 
ActiveXperts Software Forum Index -> SMS Messaging Server -> Channels
 
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
joey



Joined: 15 Feb 2008
Posts: 2

PostPosted: Fri Feb 15, 2008 4:52 am    Post subject: SQL Connection

I have installed the message server on a computer connected to the internet via dsl running windows xp, i would like to use an mssql database on the web.

The current connection string is:
"CONST STR_DATABASEFILE = "C:\Program Files\ActiveXperts\SMS Messaging Server\Projects\My Database Query Project\Database\Stock.mdb""

How would i write an mssql connection string and connect to my mssql database?
Back to top
Leon



Joined: 11 Jul 2007
Posts: 408

PostPosted: Fri Feb 15, 2008 7:25 am    Post subject:

Hello Joey,

Below is an example of a SQL server connection string. Replace the sample values with your own parameters:

Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Leon
Back to top
joey



Joined: 15 Feb 2008
Posts: 2

PostPosted: Fri Feb 15, 2008 11:25 pm    Post subject: No luck

I get this error:

02/15/2008 04:13:18 PM - [My Database Query Project.vbs] Error #29120 - Microsoft JET Database Engine: Could not find installable ISAM.; Line:124; Char:3; Code:0x80004005 (duration: 00:00)

This is my code:
Code:
Option Explicit
CONST STR_DEBUGFILE     = "C:\Program Files\ActiveXperts\SMS Messaging Server\Sys\Tmp\My Database Query Project.txt"
CONST STR_DATABASEFILE = "Driver=SQL Server;SERVER=sql3.somewhere.com;UID=test;PWD=test;"
' Declaration of global objects
Dim g_objMessageDB, g_objDebugger, g_objConstants
' Creation of global objects
Set g_objConstants      = CreateObject( "AxSmsServer.Constants" )
Set g_objMessageDB      = CreateObject( "AxSmsServer.MessageDB" )
Set g_objDebugger       = CreateObject( "ActiveXperts.VbDebugger" )
' Set Debug file - for troubleshooting purposes
g_objDebugger.DebugFile = STR_DEBUGFILE
g_objDebugger.Enabled   = False

' // ========================================================================
' // Function: ProcessMessage
' // ------------------------------------------------------------------------
' // ProcessMessage trigger function to process incoming messages
' // ========================================================================
Function ProcessMessage( numMessageID )
   Dim objMessageIn, objMessageOut
   g_objDebugger.WriteLine ">> ProcessMessage"
   ' Open the Message Database
   g_objMessageDB.Open
   If( g_objMessageDB.LastError <> 0 ) Then
      g_objDebugger.WriteLine "<< ProcessMessage,  unable to open database"
      Exit Function
   End If
   ' Retrieve the message that has just been received. If it fails then exit script
   Set objMessageIn   = g_objMessageDB.FindFirstMessage ( "ID = " & numMessageID )
   If g_objMessageDB.LastError <> 0 Then
      g_objMessageDB.Close
      g_objDebugger.WriteLine "<< ProcessMessage,  FindFirstMessage failed, error: [" & g_objMessageDB.LastError & "]"
      Exit Function
   End If
   ' Change Status to from Pending to Success. If you don't do it, the message will be processed by subsequent triggers (if defined) because message is still pending
   objMessageIn.Status = g_objConstants.MESSAGESTATUS_SUCCESS
   g_objMessageDB.Save objMessageIn   
   g_objDebugger.WriteLine "Incoming message saved, result: [" & g_objMessageDB.LastError & "]"
   ProcessQuery ( objMessageIn )
 
   ' Close the Message Database
   g_objMessageDB.Close
   g_objDebugger.WriteLine "<< ProcessMessage"
End Function

' // ========================================================================
' // ProcessQuery
' // ------------------------------------------------------------------------
' // Parse the SMS and send a response back
' // ========================================================================
Function ProcessQuery ( objMessageIn )
   Dim objMessageOut, curCurrentPrice, strReplymessage
   g_objDebugger.WriteLine ">> ProcessQuery"
   g_objDebugger.WriteLine "Selected Stock: " & objMessageIn.Body
   If( QueryStock ( objMessageIn.Body, curCurrentPrice ) = False ) Then
 strReplymessage = "test"
   Else
        strReplymessage = " " & objMessageIn.Body & " " & curCurrentPrice
   End If
     
   ' Create the reply message
   Set objMessageOut = g_objMessageDB.Create
   
   If( g_objMessageDB.LastError = 0 ) Then
     objMessageOut.Direction = g_objConstants.MESSAGEDIRECTION_OUT
     objMessageOut.Type      = g_objConstants.MESSAGETYPE_SMS
     objMessageOut.Status    = g_objConstants.MESSAGESTATUS_PENDING
     objMessageOut.Recipient = objMessageIn.Sender
     objMessageOut.ChannelID = objMessageIn.ChannelID
     objMessageOut.Body      = strReplymessage
     g_objMessageDB.Save objMessageOut
   End If
   g_objDebugger.WriteLine "<< ProcessQuery"
End Function

' // ========================================================================
' // Query stock
' // ------------------------------------------------------------------------
' // Lookup the current price of the selected stock ( use ticker symbol )
' // ========================================================================
Function QueryStock( strSymbol, BYREF curCurrentPrice )
   Dim objConn, RS
   Dim strQuery
   QueryStock = False
   g_objDebugger.WriteLine ">> QueryStock"
   Set objConn = CreateObject("ADODB.Connection")
   
   objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & STR_DATABASEFILE & ";"
   strQuery = "SELECT * FROM Stocks WHERE ID = '" & strSymbol &"'"
   
   Set RS = objConn.Execute ( strQuery )
   
   If( RS.EOF = False ) Then
     curCurrentPrice = RS( "Value" )
     QueryStock      = True
   Else
     QueryStock      = False
   End If
   ' Close database
   objConn.Close
   Set objConn = Nothing
  g_objDebugger.WriteLine "<< QueryStock"
End Function
Back to top
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum