Opening a Web Page from a Stored Procedure

  • I need to open ie from a stored procedure.

    The simplest way would seem to use xp_cmdshell and just open an instance. this however did not work.

    the code I used was:

     EXEC xp_cmdshell 'c:\progra~1\intern~1\iexplore.exe'

    So I created a dll that contains 1 function that shells out to ie and used sp_OACreate to instance the dll.

    Now I know this worked in at least some way as the dll returned a string to the grid, but still no ie window.

    Finally I ran the dll from the vb6 enviroment at set a break point to see exactly where it was going wrong.

    Unfortunatly it worked perfectly ...so why does it not work when compiled but works fine when running from vb6?

    Heres the t-SQL script:

     DECLARE @object int

     DECLARE @hr int

     DECLARE @src varchar(255), @desc varchar(255)

     EXEC @hr = sp_OACreate 'webopen.clsShell', @object OUT

     EXEC @hr = sp_OASetProperty @object, 'sPage', 'http://www.bbc.co.uk'

     EXEC @hr = sp_OAMethod @object, 'openWin'

     EXEC @hr = sp_OADestroy @object

    and heres the VB dll:

     Dim sWebPage As String

     Public Function openWin() As String

     

      If Shell("c:\progra~1\intern~1\iexplore.exe " & sPage, vbNormalFocus) Then

              openWin = "Page Should be open"

          Else

              openWin = "Failed"

      End If

     

       

     End Function

     Public Property Get sPage() As String

          sPage = sWebPage

     End Property

     Public Property Let sPage(ByVal sNewValue As String)

          sWebPage = sNewValue

     End Property

    Can anyone please help?

    Thanks in advance

     Richard Wilson

  • Just a thought

    xp_cmdshell and the sp_oa* procedures are executed on the server, while the vb app is running on your workstation.

    Did you have a look at the server? Is there IE running?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • I'm running SQL server on my local machine so I'm afraid not

    Richard

  • Hm, I don't know much about DTS, but I've just tried to create a local package with a Execute win32 task with your page as parameter.

    It worked.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • To add to myself, as IE *requires* user interaction it will appear to hang and wait for response, thus not giving back control to you when using xp_cmdshell.

    Why does it need to be a stored procedure, and not your client app?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • We need to do an action after a db update. I have no access to the client apps that will update the db.

    Have you been able to get the app to work using the dll or just the xp_cmdshell?

     

    Richard

  • No, but I doubt that there will be a difference.

    Can't you run the DTS package I've mentioned above?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • That worked. I think I need to do some research into DTS Packages.

     

    Thank you.

     

    Richard

  • hi!

    basically your IE doesn't come up because there's no handle for visual support available when running a stored procedure in the SQL server process.

    in general i must admit that what you want to achieve is really not a good idea, as SQL server is just not intended to be used in that way. even if you'll bring it up and working, it'll give you a lot of headaches ... guaranteed 😉

    best regards, chris.

  • Just wondering :

    Is it related to   'Job Security' !!!!

    -M Rai

     

Viewing 10 posts - 1 through 9 (of 9 total)

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