Novice sp_oa... question

  • I want to get the domain from SQL server. If I use our front end tool FoxPro 7 on my machine with:

    loNetWork = CREATEOBJECT('wscript.network')

    ? loNetwork.UserDomain

    I get the domain I am in. No problems with wsh being disabled etc.

    I have written:

    CREATE PROCEDURE SP_OA_WHICHDOMAIN

    AS

    DECLARE @object int -- Object variable

    DECLARE @hr int -- Error variable

    DECLARE @property varchar(255) -- Error property variable

    DECLARE @return varchar(255) -- Return error value

    DECLARE @output varchar(255) -- Error output variable

    DECLARE @source varchar(255) -- Error source variable

    DECLARE @description varchar(255) -- Error description variable

    EXEC @hr = sp_OACreate 'wscript.network', @object OUT

    EXEC @hr = sp_OAMethod @object, 'UserDomain', @return OUT

    SELECT 'The domain is ' + @return

    EXEC @hr = sp_OADestroy @object

    GO

    I have excluded the error handling for brevity, which if the return value is made to say int returns correctly(?) a data type mismatch.

    I am not getting a return value.

    I have never written automation from SQL server before so forgive any basic errors.

    Is there any other way to get this information from SQL server ?

    Thanks for any help.

  • sp_oa~ is about my least favorite. Powerful idea, not so great implementation IMO. Let's see if anyone has ideas about other ways first, if not we'll try to get this working! How often would you need to access this functionality?

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • The functionality would be used infrequently , say once per day it would probably run. I have tried to avoid automation up to now as it does look klunky but could see no way round. I was hoping there would be a function @@domain like @@servername !

  • Code works on both my workstation which is not in a domain and on my machine at work which is a member of a domain. Do you have sysadmin rights? One easy way to avoid sp_oa is to write the code in VB Script and run as a job with an ActiveX scripting task, or compile as a dll/exe and run that, either way writing the results to a file or table.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Thanks for your help - I am going to use a different way as suggested rather than sp_oa calls.

    I never did get the code to work even as sysadmin either on a domain machine or a standalone. Strange.

Viewing 5 posts - 1 through 4 (of 4 total)

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