alert from SQL to my Application

  • hello friends

    i have 2 application:App1 and App2.

    App1 Insert records in Database,i need when record inserted in db,SQL alert to App2 and send sth to App2.

    how can i do this ?

    thanks :O)

  • i googled and found xp_cmdshell to run my .exe with parameters.

    but when i use this,SQL remain in Executing query batch .. mode!

    whats wrong with this ?

    DECLARE @Parameters CHAR(30)

    SET @Parameters='"calc.exe"'

    EXEC master ..xp_cmdshell @Parameters

  • I'm only guessing here... but I'd assume that the server is waiting for the application to close, and maybe also a success / failure message to report back to you.

    What happens if you manually close the calculator on the server?

  • dr_csharp

    App1 Insert records in Database,i need when record inserted in db,SQL alert to App2 and send sth to App2.

    What language are your apps written in?

    Are they web apps?

    Please post additional information so that someone can assist you.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • bitbucket (10/18/2008)

    What language are your apps written in

    Are they web apps

    its a windows service writing with C#

  • dr_csharp.

    I would use an alternate approach - when App 1 does the insert using either a dynamic sql statement or a parameterized stored procedure with a return value. Then App1 can check for an error. No error then have App 1 invoke App2 .... otherwise notify the user of the error.

    I am not a C# programmer but have used this technique with VB6 and VB.net and found that it works quite well.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • How do you "notify" the other application?

  • Ninja's RGR'us

    Notify the 2nd app using the SHELL command for example:

    Public Const WIN_NORMAL = 1 'Open Normal

    Private Declare Function apiShellExecute Lib "shell32.dll" _

    Alias "ShellExecuteA" _

    (ByVal hwnd As Long, _

    ByVal lpOperation As String, _

    ByVal lpFile As String, _

    ByVal lpParameters As String, _

    ByVal lpDirectory As String, _

    ByVal nShowCmd As Long) _

    As Long

    Const WIN_MAX = 3 'Open Maximized

    Public Const WIN_MIN = 2 'Open Minimized

    '***Error Codes***

    Private Const ERROR_SUCCESS = 32&

    Private Const ERROR_NO_ASSOC = 31&

    Private Const ERROR_OUT_OF_MEM = 0&

    Private Const ERROR_FILE_NOT_FOUND = 2&

    Private Const ERROR_PATH_NOT_FOUND = 3&

    Private Const ERROR_BAD_FORMAT = 11&

    '***************Usage Examples***********************

    'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)

    'Call Email app: ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)

    'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)

    'Handle Unknown extensions (call Open With Dialog):

    ' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)

    'Start Access instance:

    ' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)

    '****************************************************

    Function fHandleFile(stFile As String, lShowHow As Long) As Integer

    Dim lRet As Long, varTaskID As Variant

    Dim stRet As String

    Dim hWndAccessApp As Long 'Added 5/16/06 RJMc

    'First try ShellExecute

    lRet = apiShellExecute(hWndAccessApp, vbNullString, _

    stFile, vbNullString, vbNullString, lShowHow)

    If lRet > ERROR_SUCCESS Then

    stRet = vbNullString

    lRet = -1

    Else

    Select Case lRet

    Case ERROR_NO_ASSOC:

    'Try the OpenWith dialog

    varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " _

    & stFile, WIN_NORMAL)

    lRet = (varTaskID <> 0)

    Case ERROR_OUT_OF_MEM:

    stRet = "Error: Out of Memory/Resources. Couldn't Execute!"

    Case ERROR_FILE_NOT_FOUND:

    stRet = "Error: File not found. Couldn't Execute!"

    Case ERROR_PATH_NOT_FOUND:

    stRet = "Error: Path not found. Couldn't Execute!"

    Case ERROR_BAD_FORMAT:

    stRet = "Error: Bad File Format. Couldn't Execute!"

    Case Else:

    End Select

    End If

    fHandleFile = lRet & IIf(stRet = "", vbNullString, ", " & stRet)

    End Function

    If you want App1 to wait until App 2 has finished then use SHELL with wait.

    Using:

    Option Explicit

    Private Type STARTUPINFO

    cb As Long

    lpReserved As String

    lpDesktop As String

    lpTitle As String

    dwX As Long

    dwY As Long

    dwXSize As Long

    dwYSize As Long

    dwXCountChars As Long

    dwYCountChars As Long

    dwFillAttribute As Long

    dwFlags As Long

    wShowWindow As Integer

    cbReserved2 As Integer

    lpReserved2 As Long

    hStdInput As Long

    hStdOutput As Long

    hStdError As Long

    End Type

    Private Type PROCESS_INFORMATION

    hProcess As Long

    hThread As Long

    dwProcessID As Long

    dwThreadID As Long

    End Type

    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

    Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    Private Const NORMAL_PRIORITY_CLASS = &H20&

    Private Const INFINITE = -1&

    Public Sub ExecCmd(cmdline$)

    Dim proc As PROCESS_INFORMATION

    Dim start As STARTUPINFO

    start.cb = Len(start)

    ' Shell the Application:

    ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

    ' Wait for the shelled application to finish:

    ret& = WaitForSingleObject(proc.hProcess, INFINITE)

    ret& = CloseHandle(proc.hProcess)

    End Sub

    '

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply