Showing posts with label xp_cmdshell. Show all posts
Showing posts with label xp_cmdshell. Show all posts

Tuesday, March 27, 2012

Calling SSIS packages from a Service Broker Queue

I would like to call an SSIS package from a Service Broker Queue.

There is one way that I am aware of -

Using xp_cmdshell from within an activation stored procedure and using DTEXEC.

Is there a more elegant way of executing an SSIS package from within SSB?

Also, I am not interested in writing a .NET external activator to process my messages in the queue. I would like this operation to be strictly database oriented. Having said this, I am also trying to avoid triggers processing the messages in the queue.

Thank you!

SQLCLR with unsafe assembly (in order to call Process.Start()) would be slightly better option than xp_cmdshell. Even then, starting external processes from an activated stored procedure is limiting and dangerous. Limiting because you can only start the external application as the service account running sqlservr.exe. Dangerous because if the process fails to start (eg> out of memory), you may orphan messages in the queue since there will be no process to process them.

You might want to look at the External Activator sample (linked from www.sqlservicebroker.com) and adapt it or build something similar.

I don't know what you mean by "triggers processing the messages in the queue". SQL Server 2005 has no triggers for queues.

Rushi

|||

We use this mechanism to farm out data warehouse ETL mechanism and it works fairly well.

Once you start up SSIS, though, your package should be the one that reaches back into the DB and pulls messages off the queue. Make sure to put your transaction logic, error handling, etc. in the SSIS control flow, taking into account what should be done with messages in the context of your package.

There's a ton of SSIS overhead (at least compared with pulling a message off a queue), so if you're getting a fair number of messages, you don't want to start up the engine each time you want to process a message. We opted to call out to dtexec rather than have a separate service running, although I think that's a matter of preference (and your level of comfort/concern of running external processes from SQL vs. having to install/manage other services).

|||

Couldn't you just create a SQLCLR stored procedure to execute the package directly & with full transactional support? I.e. Have an activated stored proc, authored in C#, executing the SSIS package without doing any "shelling out".

Something like the link below implemented as a SQLCLR proc?

http://www.codeproject.com/useritems/CallSSISFromCSharp.asp?df=100&forumid=309846&exp=0&select=1519306

Calling SSIS packages from a Service Broker Queue

I would like to call an SSIS package from a Service Broker Queue.

There is one way that I am aware of -

Using xp_cmdshell from within an activation stored procedure and using DTEXEC.

Is there a more elegant way of executing an SSIS package from within SSB?

Also, I am not interested in writing a .NET external activator to process my messages in the queue. I would like this operation to be strictly database oriented. Having said this, I am also trying to avoid triggers processing the messages in the queue.

Thank you!

SQLCLR with unsafe assembly (in order to call Process.Start()) would be slightly better option than xp_cmdshell. Even then, starting external processes from an activated stored procedure is limiting and dangerous. Limiting because you can only start the external application as the service account running sqlservr.exe. Dangerous because if the process fails to start (eg> out of memory), you may orphan messages in the queue since there will be no process to process them.

You might want to look at the External Activator sample (linked from www.sqlservicebroker.com) and adapt it or build something similar.

I don't know what you mean by "triggers processing the messages in the queue". SQL Server 2005 has no triggers for queues.

Rushi

|||

We use this mechanism to farm out data warehouse ETL mechanism and it works fairly well.

Once you start up SSIS, though, your package should be the one that reaches back into the DB and pulls messages off the queue. Make sure to put your transaction logic, error handling, etc. in the SSIS control flow, taking into account what should be done with messages in the context of your package.

There's a ton of SSIS overhead (at least compared with pulling a message off a queue), so if you're getting a fair number of messages, you don't want to start up the engine each time you want to process a message. We opted to call out to dtexec rather than have a separate service running, although I think that's a matter of preference (and your level of comfort/concern of running external processes from SQL vs. having to install/manage other services).

|||

Couldn't you just create a SQLCLR stored procedure to execute the package directly & with full transactional support? I.e. Have an activated stored proc, authored in C#, executing the SSIS package without doing any "shelling out".

Something like the link below implemented as a SQLCLR proc?

http://www.codeproject.com/useritems/CallSSISFromCSharp.asp?df=100&forumid=309846&exp=0&select=1519306

Tuesday, March 20, 2012

Calling Executables from SQL Server and getting return value.

Hi All,

I have a requirement of calling a Executable from SQL Server.
I know we can use -

EXEC @.result = Master..xp_cmdshell @.<command_string
However I want to get the return value (int) from the executable.
xp_cmdshell always returns 0 or 1. How can the executable return code
say 99 be obtained in SQL Server?

Thanks & Regards,
Chandra MohanThis is a bit of a kludge, but one method is to execute your application
via a CMD file and ECHO the %ERRORLEVEL% so that it is returned in the
xp_cmdshell resultset for subsequent interrogation. For example

MyApp.cmd

@.MyApplication.EXE
@.ECHO APPLICATION RETURN CODE=%ERRORLEVEL%

SQL script:

SET NOCOUNT ON
DECLARE @.ReturnCode int
DECLARE @.ApplicationReturnCode int
CREATE TABLE #Messages(Message nvarchar(255))
INSERT INTO #Messages
EXEC @.ReturnCode = master..xp_cmdshell 'c:\MyApp\MyApp.cmd'
SELECT @.ApplicationReturnCode =
CAST(SUBSTRING(Message, 25, 10) AS int)
FROM #Messages
WHERE LEFT(Message, 24) = 'APPLICATION RETURN CODE='
SELECT
@.ReturnCode,
@.ApplicationReturnCode
DROP TABLE #Messages
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Chandra Mohan" <bschandramohan@.yahoo.com> wrote in message
news:bb0ef6.0308250314.77157f14@.posting.google.com ...
> Hi All,
> I have a requirement of calling a Executable from SQL Server.
> I know we can use -
> EXEC @.result = Master..xp_cmdshell @.<command_string>
> However I want to get the return value (int) from the executable.
> xp_cmdshell always returns 0 or 1. How can the executable return code
> say 99 be obtained in SQL Server?
> Thanks & Regards,
> Chandra Mohan

Calling an executable file from stored procedure

Hi people.

I have this issue

I'm on a application server and i need to run a executable file from a SP, my problem is if i use xp_cmdshell (from the SP) it will try to run it on the SQL Server not on a App server, this a third party executable so cannnot be run on the sql backend.

Do you know any workaround for this?have the client launch it on it's own.

what business does the server have launching apps on the client anyway?|||jez,

you never call a report engine or a command line DOS thingie from you application code?|||Hi people.

I have this issue

I'm on a application server and i need to run a executable file from a SP, my problem is if i use xp_cmdshell (from the SP) it will try to run it on the SQL Server not on a App server, this a third party executable so cannnot be run on the sql backend.

Do you know any workaround for this?

Is this executable a GUI? If so, don't do it...it could hose everything

If it's just like a bat file, or a batch process then you should be fine|||Actually is a exe file with some parameters (not GUI)

Picture this

Server A
Application Server

Server B
SQL Server 2005

on Server A, i'm executing a SP wich is located on Server B if i use xp_cmdshell is going to look on server B but the exe file is located on server A... can i do like a Remote Execution?|||Why wouldn't you place the executable on both servers?|||won't work the executable on the SQL Server by itself, i need to install the whole application and we don't have the license for it.|||Can't your xp_cmdshell just include the complete path to the executable?

as in xp_cmdshell '\\MyRemoteServer\MysteryJob\DoSomething.bat' works fine where I live.

Worst case you could have your bat file start the exe. We do some of that, though it's too close to 5:30 on Friday for me to make a decent effort at finding the applicable code at this time.|||jez,

you never call a report engine or a command line DOS thingie from you application code?

sure, but that's not how I read the question.

how I read it was, "how do I launch an exe that lives on the client from a stored procedure on the server?"

perhaps I misinterpreted.

Calling an application from SQL (xp_cmdshell)

Hi,

I am trying to run an executable from MS SQL Server 2000. I tried using the commands:

EXEC master..xp_cmdshell '"\\comp1\c\test.exe"', NO_OUTPUT

and

EXEC master..xp_cmdshell 'Start Test "\\comp1\c\test.exe" , NO_OUTPUT

When I go to task manager on comp1 I see that the process is listed as running only under Processes, not under Application. In addition the application doesnt seem to execute properly and the SQL Query doesnt terminate. For testing processes I have just a small VB project that pops up a message box and then exits (it works fine by running it from windows). I never see the message box, nor does it exit the process.

If I try to manually cancel the SQL Query, it still will not stop until I kill the process for test.exe from the task manager.

Does anyone have any ideas on how I could get the query to terminate properly and how to get the executable to do its thing?

Sincerely,
Andrei Girenkovyeah...don't call gui apps from xp_cmdshell unless you want to hang your server...

Only use batch executables that don't require ANY prompting...|||Well I wasn't aware of that, however the executable I'm trying to launch actually doesnt have any sort of GUI...all it does is checks some output from another program and updates some DB tables.

I found that after launching the executable through double clicking it worked fine, but when launching it from SQL it didn't update the DB. I made the small project with the message box as an easier way of testing it rather than having to go to SQL every time and checking whether or not a table got updated.

~Andrei|||Can you be more specific as to what this executable is doing ?|||[i]I made the small project with the message box
~Andrei

You don't think a message box is a gui?|||I mean the actual executable I am trying to run has no GUI. The messagebox program is only for testing. I now scrapped the message box project because of the GUI and am trying to just run/test with the actual executable, however I am not seeing any results either.

My program does the following: I am trying to record the Volume Serial of the C drive of the machine the instance of the SQL server is running. I have an executable which reads the volume serial, scrambles it, records it into the DB, and then exits out. It takes as a command line argument the name of the instance of SQL server on that machine.

I am trying to write a stored procedure that I could call which would run this executable and pass it the instance name as an argument. The call in the stored procedure is the following:

EXEC master..xp_cmdshell '"C:\volumeserial.exe" -' + (select @.@.SERVERNAME), NO_OUTPUT

Right now the select @.@.SERVERNAME part is hardcoded to the server name because I was getting an syntax error at the + before the select statement, and the comma after it. It actually looks like this:

EXEC master..xp_cmdshell '"C:\volumeserial.exe" -InstanceName', NO_OUTPUT

When I call this stored procedure I can see in the task manager under processes that Volumeserial.exe is running, however the DB doesnt get updated, the process never terminates, and the stored procedure never gets past that line. Like I mentioned earlier, the program works fine if I call it from outside SQL, so I think it's a SQL issue.

~Andrei Girenkov|||One thing to double check would be the connection string to the database. If you are using a trusted connection, remember that the application will be running under the identity of the SQL Server Service account.

Another thing to check would be permissions on the executable. Again, be sure that the SQL Server Service account as execute permissions on the application executable.

Make sure that you test you application executable while logged in as the SQL Server service account.

Regards,

hmscott|||My SQL Server Service account is the Administrator. I can run the executable just fine when logged in as Administrator.

~Andrei|||how about making the executable just return the scrambled serial number without trying to connect to the server and do the update? you can do those things in your stored procedure.

create table #tmp ([output] nvarchar(4000) null)
insert #tmp EXEC master..xp_cmdshell 'C:\volumeserial.exe'
delete #tmp where [output] is null
update y set scrambled_serial = [output]
from your_table y, #tmp where y.drive_letter = 'C'|||Thank you everyone for all your help. I had a hunch that it was not connecting to SQL properly so instead of writing the value back to the DB I had the program write it out to a file along with the command line arguments. It turned out that the problem was caused because in SQL I was passing the InstanceName parameter to the program with a dash (-). The program wasn't expecting that.

The other problem of not being able to select @.@.ServerName was fixed by just declaring the whole string as a varchar() and passing that variable to xp_cmdshell instead of the concatinated string.

Thanks again everybody who helped

~Andreisql

Thursday, March 8, 2012

Calling a .Net application via a COM wrapper in SQL Server 2005

You should really go another route. Having SQL Server execute code hosted by
CLR was never supported
though spOACreate nor xp_cmdshell. I'd consider re-writing that com object a
s a CLR stored procedure
and you are in a supported environment. Below is my general "canned" respons
e:
It is not supported for extended stored procedures or sp_OA procedures to ca
ll .NET code in CLR;
hosted within SQL Server's adress space..
See:
http://support.microsoft.com/defaul...kb;en-us;322884
Also, below is witnh permission from David Browne, explaining how you can ha
ve SQL Server execute
CLR code executing in its own process:
"
Short answer: Don't do it.
Calling managed code inside a stored procedure is not supported.
http://support.microsoft.com/defaul...kb;en-us;322884
At least not directly. You need some sort of unmanaged proxy to communicate
with your component running in another process.
For instance, http, or, drum roll, a COM+ Server Application.
This will cause COM+ to load an unmanaged proxy object in the SqlServer
process and will load the CLR into a COM+ surrogate process (dllhost.exe).
Which somebody here mentioned last week, and I just got around to testing.
It's all perfectly transparent to you, but you have to set up the COM+
server application.
Remember this is something different from .net remoting. With .NET remoting
you have a _managed_ proxy object in the local process, and so you load the
CLR in the local process as well as the remote process.
Anyway here's what I did:
I created this VB class
comTest.vb listing:
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual),
ProgId("comTest.comTestClass")> _
Public Class comTest
Public Function Hello() As String
Return "hello"
End Function
End Class
build comTest.dll and registered it with
regasm /codebase comTest.dll /tlb:comTest.tlb
(complains that I haven't strong-named my assembly, which you should do.)
created an empty COM+ server application, set to run under a local
administrator account, and dragged comTest.dll into its components folder.
created an unmanaged host (vbscript will do), and invoked the component
using IDispach just like SQLServer.
test.vbs listing
Set d = CreateObject("comTest.comTestClass")
MsgBox d.Hello
Then I used the .net command line debugger cordbg.exe's 'pro' command to
list the processes hosting the CLR. And procexp.exe from
www.sysinternals.com to verify that the CLR's dll's were not loaded in my
unmanaged process. My unmanaged host did not load the CLR, although it
loaded "comsvcs.dll", and the CLR was loaded by the dllhost.exe process.
Then in sql I ran
declare @.object int
declare @.msg varchar(50)
declare @.rc int
declare @.hr int
declare @.source varchar(1000)
declare @.description varchar(1000)
exec @.rc = sp_oacreate 'comTest.comTestClass', @.object output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'create failed ' + @.description
return
end
exec @.rc = sp_oamethod @.object, 'Hello', @.msg output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'method failed ' + @.description
return
end
print 'return: ' + @.msg
exec @.rc = sp_oadestroy @.object
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'destroy failed ' + @.description
return
end
Ran fine, and still only one CLR loaded into dllhost.exe's process. So
think we can safely conclude that COM+ server applications do not violate
the prohibition against running managed code in SQLServer's process and
provide a convenient mechanism for interoperating with managed code from
TSQL.
David
"
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:EC73FFA6-3F3E-47EE-809E-18BF1D60A88E@.microsoft.com...
>I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
> the option COM Interop set to True. Once built, the VS2003 project solutio
n
> produces a .tlb file. A setup is produced (from within VS2003) that includ
es
> the dll and tlb files. These are installed on a PC (running on Windows
> 2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (w
ith
> the latest SQL Server 2000 Service Pack). A trigger fired from one of the
> tables in our own database (within SQL Server 2000) makes the calls to the
> COM wrapped assembly.
> CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
> FOR INSERT, UPDATE,DELETE
> AS
> DECLARE @.hr int
> DECLARE @.factory int
> DECLARE @.xalert int
> DECLARE @.response int
> DECLARE @.errMsg varchar(8000)
> DECLARE @.success bit
> EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUT
PUT
> select @.hr
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
> @.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactor
y',
> 'http://localhost:8080/axis/services/xalertsport'
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
> 'MyXalerts55_030506_ss', 1100
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.xalert , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> IF (@.success = 0)
> BEGIN
> EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> END
> EXEC @.hr = sp_OADestroy @.xalert
> EXEC @.hr = sp_OADestroy @.response
> EXEC @.hr = sp_OADestroy @.factory
>
> This works fine and we are able to create the objects and make the method
> calls on it.
> We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
> VS2005, using the same settings as before. A new setup was created and
> installed on a PC running on Windows 2000 Server and has SQL Server 2005 S
P1
> installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
> database and our own databse have been made "trustworthy". The assembly
> created above (with .net 2,.0) has been created within SQL Server, setting
> External_acesss (tried unsafe as well) permissions on it.
> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
>
> We have tried to put more COM Wrapper around the generated tlb , but that
> has not worked - giving the same error. Using .net 1.1 assembly (same one
as
> used for SQLServer 2000) , we get the same error. However, It is possible
to
> create other standard COM objects (like the SQLDMO objects), using the
> sp_oacreate. So, it may be something particular to .net assemblies being
> called (via the COM interop wrapper) from SQL Server 2005.I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
the option COM Interop set to True. Once built, the VS2003 project solution
produces a .tlb file. A setup is produced (from within VS2003) that includes
the dll and tlb files. These are installed on a PC (running on Windows
2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (wit
h
the latest SQL Server 2000 Service Pack). A trigger fired from one of the
tables in our own database (within SQL Server 2000) makes the calls to the
COM wrapped assembly.
CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
FOR INSERT, UPDATE,DELETE
AS
DECLARE @.hr int
DECLARE @.factory int
DECLARE @.xalert int
DECLARE @.response int
DECLARE @.errMsg varchar(8000)
DECLARE @.success bit
EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUTPU
T
select @.hr
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.factory , @.hr
RETURN
END
EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
@.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactory'
,
'http://localhost:8080/axis/services/xalertsport'
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.factory , @.hr
RETURN
END
EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
'MyXalerts55_030506_ss', 1100
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.xalert , @.hr
RETURN
END
EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.response , @.hr
RETURN
END
IF (@.success = 0)
BEGIN
EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.response , @.hr
RETURN
END
END
EXEC @.hr = sp_OADestroy @.xalert
EXEC @.hr = sp_OADestroy @.response
EXEC @.hr = sp_OADestroy @.factory
This works fine and we are able to create the objects and make the method
calls on it.
We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
VS2005, using the same settings as before. A new setup was created and
installed on a PC running on Windows 2000 Server and has SQL Server 2005 SP1
installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
database and our own databse have been made "trustworthy". The assembly
created above (with .net 2,.0) has been created within SQL Server, setting
External_acesss (tried unsafe as well) permissions on it.
We are using the same trigger as above and the same code within the trigger.
The trigger fails on the sp_oacreate line with the following error.
OLE Automation Error
HRESULT: 0x80131700
Source: ODSOLE EXtended Procedure
We have tried to put more COM Wrapper around the generated tlb , but that
has not worked - giving the same error. Using .net 1.1 assembly (same one as
used for SQLServer 2000) , we get the same error. However, It is possible to
create other standard COM objects (like the SQLDMO objects), using the
sp_oacreate. So, it may be something particular to .net assemblies being
called (via the COM interop wrapper) from SQL Server 2005.|||You should really go another route. Having SQL Server execute code hosted by
CLR was never supported
though spOACreate nor xp_cmdshell. I'd consider re-writing that com object a
s a CLR stored procedure
and you are in a supported environment. Below is my general "canned" respons
e:
It is not supported for extended stored procedures or sp_OA procedures to ca
ll .NET code in CLR;
hosted within SQL Server's adress space..
See:
http://support.microsoft.com/defaul...kb;en-us;322884
Also, below is witnh permission from David Browne, explaining how you can ha
ve SQL Server execute
CLR code executing in its own process:
"
Short answer: Don't do it.
Calling managed code inside a stored procedure is not supported.
http://support.microsoft.com/defaul...kb;en-us;322884
At least not directly. You need some sort of unmanaged proxy to communicate
with your component running in another process.
For instance, http, or, drum roll, a COM+ Server Application.
This will cause COM+ to load an unmanaged proxy object in the SqlServer
process and will load the CLR into a COM+ surrogate process (dllhost.exe).
Which somebody here mentioned last week, and I just got around to testing.
It's all perfectly transparent to you, but you have to set up the COM+
server application.
Remember this is something different from .net remoting. With .NET remoting
you have a _managed_ proxy object in the local process, and so you load the
CLR in the local process as well as the remote process.
Anyway here's what I did:
I created this VB class
comTest.vb listing:
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual),
ProgId("comTest.comTestClass")> _
Public Class comTest
Public Function Hello() As String
Return "hello"
End Function
End Class
build comTest.dll and registered it with
regasm /codebase comTest.dll /tlb:comTest.tlb
(complains that I haven't strong-named my assembly, which you should do.)
created an empty COM+ server application, set to run under a local
administrator account, and dragged comTest.dll into its components folder.
created an unmanaged host (vbscript will do), and invoked the component
using IDispach just like SQLServer.
test.vbs listing
Set d = CreateObject("comTest.comTestClass")
MsgBox d.Hello
Then I used the .net command line debugger cordbg.exe's 'pro' command to
list the processes hosting the CLR. And procexp.exe from
www.sysinternals.com to verify that the CLR's dll's were not loaded in my
unmanaged process. My unmanaged host did not load the CLR, although it
loaded "comsvcs.dll", and the CLR was loaded by the dllhost.exe process.
Then in sql I ran
declare @.object int
declare @.msg varchar(50)
declare @.rc int
declare @.hr int
declare @.source varchar(1000)
declare @.description varchar(1000)
exec @.rc = sp_oacreate 'comTest.comTestClass', @.object output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'create failed ' + @.description
return
end
exec @.rc = sp_oamethod @.object, 'Hello', @.msg output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'method failed ' + @.description
return
end
print 'return: ' + @.msg
exec @.rc = sp_oadestroy @.object
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'destroy failed ' + @.description
return
end
Ran fine, and still only one CLR loaded into dllhost.exe's process. So
think we can safely conclude that COM+ server applications do not violate
the prohibition against running managed code in SQLServer's process and
provide a convenient mechanism for interoperating with managed code from
TSQL.
David
"
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:EC73FFA6-3F3E-47EE-809E-18BF1D60A88E@.microsoft.com...
>I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
> the option COM Interop set to True. Once built, the VS2003 project solutio
n
> produces a .tlb file. A setup is produced (from within VS2003) that includ
es
> the dll and tlb files. These are installed on a PC (running on Windows
> 2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (w
ith
> the latest SQL Server 2000 Service Pack). A trigger fired from one of the
> tables in our own database (within SQL Server 2000) makes the calls to the
> COM wrapped assembly.
> CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
> FOR INSERT, UPDATE,DELETE
> AS
> DECLARE @.hr int
> DECLARE @.factory int
> DECLARE @.xalert int
> DECLARE @.response int
> DECLARE @.errMsg varchar(8000)
> DECLARE @.success bit
> EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUT
PUT
> select @.hr
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
> @.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactor
y',
> 'http://localhost:8080/axis/services/xalertsport'
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
> 'MyXalerts55_030506_ss', 1100
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.xalert , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> IF (@.success = 0)
> BEGIN
> EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> END
> EXEC @.hr = sp_OADestroy @.xalert
> EXEC @.hr = sp_OADestroy @.response
> EXEC @.hr = sp_OADestroy @.factory
>
> This works fine and we are able to create the objects and make the method
> calls on it.
> We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
> VS2005, using the same settings as before. A new setup was created and
> installed on a PC running on Windows 2000 Server and has SQL Server 2005 S
P1
> installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
> database and our own databse have been made "trustworthy". The assembly
> created above (with .net 2,.0) has been created within SQL Server, setting
> External_acesss (tried unsafe as well) permissions on it.
> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
>
> We have tried to put more COM Wrapper around the generated tlb , but that
> has not worked - giving the same error. Using .net 1.1 assembly (same one
as
> used for SQLServer 2000) , we get the same error. However, It is possible
to
> create other standard COM objects (like the SQLDMO objects), using the
> sp_oacreate. So, it may be something particular to .net assemblies being
> called (via the COM interop wrapper) from SQL Server 2005.|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> You should really go another route. Having SQL Server execute code hosted
> by CLR was never supported though spOACreate nor xp_cmdshell. I'd consider
> re-writing that com object as a CLR stored procedure and you are in a
> supported environment. Below is my general "canned" response:
> It is not supported for extended stored procedures or sp_OA procedures to
> call .NET code in CLR; hosted within SQL Server's adress space..
> See:
> http://support.microsoft.com/defaul...kb;en-us;322884
> Also, below is witnh permission from David Browne, explaining how you can
> have SQL Server execute CLR code executing in its own process:
>
Thanks,
But if I understand the question, the OP has compiled and installed the
assembly in SQL CLR. If so, he just needs to issue write a CLR stored
procedure in .NET that implements the trigger logic. Accessing the assembly
the OLE Automation stored procedures is no longer necessary. The trigger
body just needs to invoke a CLR stored procedure.
David|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> You should really go another route. Having SQL Server execute code hosted
> by CLR was never supported though spOACreate nor xp_cmdshell. I'd consider
> re-writing that com object as a CLR stored procedure and you are in a
> supported environment. Below is my general "canned" response:
> It is not supported for extended stored procedures or sp_OA procedures to
> call .NET code in CLR; hosted within SQL Server's adress space..
> See:
> http://support.microsoft.com/defaul...kb;en-us;322884
> Also, below is witnh permission from David Browne, explaining how you can
> have SQL Server execute CLR code executing in its own process:
>
Thanks,
But if I understand the question, the OP has compiled and installed the
assembly in SQL CLR. If so, he just needs to issue write a CLR stored
procedure in .NET that implements the trigger logic. Accessing the assembly
the OLE Automation stored procedures is no longer necessary. The trigger
body just needs to invoke a CLR stored procedure.
David|||Yes, I fully agree. However, the first post indicates that this isn't what t
he OP had in mind. Or
perhaps the first post seemed a bit ambiguous on this:

> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
Thanks for making that option explicit, though. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in messa
ge
news:%23Hf3w3dmGHA.4536@.TK2MSFTNGP04.phx.gbl...
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> Thanks,
> But if I understand the question, the OP has compiled and installed the as
sembly in SQL CLR. If
> so, he just needs to issue write a CLR stored procedure in .NET that imple
ments the trigger logic.
> Accessing the assembly the OLE Automation stored procedures is no longer n
ecessary. The trigger
> body just needs to invoke a CLR stored procedure.
> David|||Yes, I fully agree. However, the first post indicates that this isn't what t
he OP had in mind. Or
perhaps the first post seemed a bit ambiguous on this:

> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
Thanks for making that option explicit, though. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in messa
ge
news:%23Hf3w3dmGHA.4536@.TK2MSFTNGP04.phx.gbl...
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> Thanks,
> But if I understand the question, the OP has compiled and installed the as
sembly in SQL CLR. If
> so, he just needs to issue write a CLR stored procedure in .NET that imple
ments the trigger logic.
> Accessing the assembly the OLE Automation stored procedures is no longer n
ecessary. The trigger
> body just needs to invoke a CLR stored procedure.
> David

call to xp_cmdshell from trigger problem

To any SQL Server MVP:
We have a problem that out group can not seem to resolve. We have a
database that is used to alert and calculate required amounts of assistance
to clients that monitor through a private frame relay WAN. When a problem
occurs client 1 enters the request at a workstation which updates the
database and causes a trigger to fire and starts a process to notify the
other clients that assistance is required. This portion has been in use for
several years but now need to send information to a control area system,
rather than single entity, that is in XML format so a program was created to
take the data and format in accordance to the XML Schema rules the area
used.
At first it failed because the trigger called the EXE but the tables were
locked by the first program called in the trigger. To resolve this and
allow the trigger to continue thus unlocking the tables we changed the
trigger to call a vbs script file rather than the EXE directly. This seemed
to resolve the situation with locked tables in the database but a new issue
has come up I can not figure out.
The EXE has to use a X509 digital certificate to pass the data to the
client's server. When I run the EXE from the command line it works, when I
use SQL Query Manager and run the trigger code (less the alert portion) it
works but when the trigger fires is fails to send the information. It builds
everything but the client never gets the XML stream? We currently use
simple text files to track where the program process is but this file
indicates it finishes properly and all cleanup of objects occurs (Code in
VB6 and we use WinHTTP Request Object 5.1). The code has been altered to
indicate within the text file who started the program and this indicates the
"SQLProxy" account is who is running the EXE file. It almost seems that when
impersonate process occurs the local server does not treat the SQLProxy
account as the right one?
How can we test using SQL Query Manager the exact process as when the
trigger is fired from SQL Server?
Information:
ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called from
the trigger by the application user. This is what we created as instructed
by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
works because the first step in the trigger works.
CERTIFICATE: We logged on to the server using SQLProxy so the
certificate could be installed into the "My" store for the user. We could
move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
Hi Daniel,
I am just wondering under what user you did your test on query analyzer.
Have you tried the following to see what kind of result you get:
1. log in on the server by using your SQLProxy
2. Open query analyzer and connect to the server with Windows Authentication
3. try a test and see if the client gets the required info.
Sasan Saidi
Senior DBA
"Daniel Gard" wrote:

> To any SQL Server MVP:
> We have a problem that out group can not seem to resolve. We have a
> database that is used to alert and calculate required amounts of assistance
> to clients that monitor through a private frame relay WAN. When a problem
> occurs client 1 enters the request at a workstation which updates the
> database and causes a trigger to fire and starts a process to notify the
> other clients that assistance is required. This portion has been in use for
> several years but now need to send information to a control area system,
> rather than single entity, that is in XML format so a program was created to
> take the data and format in accordance to the XML Schema rules the area
> used.
> At first it failed because the trigger called the EXE but the tables were
> locked by the first program called in the trigger. To resolve this and
> allow the trigger to continue thus unlocking the tables we changed the
> trigger to call a vbs script file rather than the EXE directly. This seemed
> to resolve the situation with locked tables in the database but a new issue
> has come up I can not figure out.
> The EXE has to use a X509 digital certificate to pass the data to the
> client's server. When I run the EXE from the command line it works, when I
> use SQL Query Manager and run the trigger code (less the alert portion) it
> works but when the trigger fires is fails to send the information. It builds
> everything but the client never gets the XML stream? We currently use
> simple text files to track where the program process is but this file
> indicates it finishes properly and all cleanup of objects occurs (Code in
> VB6 and we use WinHTTP Request Object 5.1). The code has been altered to
> indicate within the text file who started the program and this indicates the
> "SQLProxy" account is who is running the EXE file. It almost seems that when
> impersonate process occurs the local server does not treat the SQLProxy
> account as the right one?
> How can we test using SQL Query Manager the exact process as when the
> trigger is fired from SQL Server?
>
> Information:
> ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called from
> the trigger by the application user. This is what we created as instructed
> by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
> works because the first step in the trigger works.
> CERTIFICATE: We logged on to the server using SQLProxy so the
> certificate could be installed into the "My" store for the user. We could
> move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
>
>
>
>
>
|||Sasan
We have tried all of the following:
1. Logged on to the Windows server as the Domain Administrator and
connecting to SQL Server using windows authentication.
2. Logged on to the Windows server as the SQLProxy Account and connecting
to SQL Server using windows authentication.
We did notice is logged on to the Windows server as either 1 or 2 and
logging onto the SQL Server as the application user it does not work.
Thanks
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> Hi Daniel,
> I am just wondering under what user you did your test on query analyzer.
> Have you tried the following to see what kind of result you get:
> 1. log in on the server by using your SQLProxy
> 2. Open query analyzer and connect to the server with Windows
Authentication[vbcol=seagreen]
> 3. try a test and see if the client gets the required info.
> Sasan Saidi
> Senior DBA
> "Daniel Gard" wrote:
assistance[vbcol=seagreen]
problem[vbcol=seagreen]
for[vbcol=seagreen]
created to[vbcol=seagreen]
were[vbcol=seagreen]
seemed[vbcol=seagreen]
issue[vbcol=seagreen]
when I[vbcol=seagreen]
it[vbcol=seagreen]
builds[vbcol=seagreen]
in[vbcol=seagreen]
to[vbcol=seagreen]
the[vbcol=seagreen]
when[vbcol=seagreen]
from[vbcol=seagreen]
instructed[vbcol=seagreen]
could[vbcol=seagreen]
|||Sasan
The application user is a SQL Server account and not a Windows user account.
We noticed the following behavior. If the application user account was
placed into the SQL System Administrator group the program runsa as the
Domain account for the SQL Server and if this user is not a in the
administrator group then the program runs as SQLProxy.
The more I mess with this the more I think the user running the application
after the call from SQL Server can not find the digital certificate in the
CURRENT_USER\My store. How does the impersonation really work with SQL
Server?
Thanks
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> Hi Daniel,
> I am just wondering under what user you did your test on query analyzer.
> Have you tried the following to see what kind of result you get:
> 1. log in on the server by using your SQLProxy
> 2. Open query analyzer and connect to the server with Windows
Authentication[vbcol=seagreen]
> 3. try a test and see if the client gets the required info.
> Sasan Saidi
> Senior DBA
> "Daniel Gard" wrote:
assistance[vbcol=seagreen]
problem[vbcol=seagreen]
for[vbcol=seagreen]
created to[vbcol=seagreen]
were[vbcol=seagreen]
seemed[vbcol=seagreen]
issue[vbcol=seagreen]
when I[vbcol=seagreen]
it[vbcol=seagreen]
builds[vbcol=seagreen]
in[vbcol=seagreen]
to[vbcol=seagreen]
the[vbcol=seagreen]
when[vbcol=seagreen]
from[vbcol=seagreen]
instructed[vbcol=seagreen]
could[vbcol=seagreen]
|||When xp_cmdshell is invoked by a user who is a member of the sysadmin fixed
server role, xp_cmdshell will be executed under the security context in which
the SQL Server service is running. When the user is not a member of the
sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy
account, which is specified using xp_sqlagent_proxy_account. If the proxy
account is not available, xp_cmdshell will fail.
Sasan
"Daniel Gard" wrote:

> Sasan
> The application user is a SQL Server account and not a Windows user account.
> We noticed the following behavior. If the application user account was
> placed into the SQL System Administrator group the program runsa as the
> Domain account for the SQL Server and if this user is not a in the
> administrator group then the program runs as SQLProxy.
> The more I mess with this the more I think the user running the application
> after the call from SQL Server can not find the digital certificate in the
> CURRENT_USER\My store. How does the impersonation really work with SQL
> Server?
> Thanks
> Dan
>
> "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> Authentication
> assistance
> problem
> for
> created to
> were
> seemed
> issue
> when I
> it
> builds
> in
> to
> the
> when
> from
> instructed
> could
>
>
|||Sasan
I understand that and we have all of this working. The problem seems very
strange even in my book because I am not sure if the impersonation process
uses a modified SID from the one if you log on the the server using the same
account. Does it take the domain user and create a temporary local account?
If so then that is the problem and this user can not find the certificate.
We are going to try to use a public certificate store and see if the process
will complete.
The program we wrote runs no matter what method the difference is when run
from the command line or from SQL Query manager it finishes by sending XML
to the the client but if the same process runs from being called by the vbs
script that is called by the trigger the client get nothing.
Thanks
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:7C116F51-C3BB-4ADD-96FC-9231D90287BE@.microsoft.com...
> When xp_cmdshell is invoked by a user who is a member of the sysadmin
fixed
> server role, xp_cmdshell will be executed under the security context in
which[vbcol=seagreen]
> the SQL Server service is running. When the user is not a member of the
> sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy
> account, which is specified using xp_sqlagent_proxy_account. If the proxy
> account is not available, xp_cmdshell will fail.
> Sasan
> "Daniel Gard" wrote:
account.[vbcol=seagreen]
application[vbcol=seagreen]
the[vbcol=seagreen]
analyzer.[vbcol=seagreen]
the[vbcol=seagreen]
the[vbcol=seagreen]
use[vbcol=seagreen]
system,[vbcol=seagreen]
area[vbcol=seagreen]
and[vbcol=seagreen]
the[vbcol=seagreen]
This[vbcol=seagreen]
new[vbcol=seagreen]
the[vbcol=seagreen]
works,[vbcol=seagreen]
portion)[vbcol=seagreen]
It[vbcol=seagreen]
use[vbcol=seagreen]
file[vbcol=seagreen]
(Code[vbcol=seagreen]
altered[vbcol=seagreen]
indicates[vbcol=seagreen]
that[vbcol=seagreen]
SQLProxy[vbcol=seagreen]
the[vbcol=seagreen]
called[vbcol=seagreen]
it[vbcol=seagreen]
|||Daniel, I am not sure if this can help in any ways but you might want to have
a quick look at it:
Article: Setting the Default Process Security Level Using VBScript
Link:
http://msdn.microsoft.com/library/de...v bscript.asp
Sasan
"Daniel Gard" wrote:

> Sasan
> I understand that and we have all of this working. The problem seems very
> strange even in my book because I am not sure if the impersonation process
> uses a modified SID from the one if you log on the the server using the same
> account. Does it take the domain user and create a temporary local account?
> If so then that is the problem and this user can not find the certificate.
> We are going to try to use a public certificate store and see if the process
> will complete.
> The program we wrote runs no matter what method the difference is when run
> from the command line or from SQL Query manager it finishes by sending XML
> to the the client but if the same process runs from being called by the vbs
> script that is called by the trigger the client get nothing.
> Thanks
> "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> news:7C116F51-C3BB-4ADD-96FC-9231D90287BE@.microsoft.com...
> fixed
> which
> account.
> application
> the
> analyzer.
> the
> the
> use
> system,
> area
> and
> the
> This
> new
> the
> works,
> portion)
> It
> use
> file
> (Code
> altered
> indicates
> that
> SQLProxy
> the
> called
> it
>
>
|||Sasan,
I'll look this over maybe there is something we missed in the vbs script
being called by the trigger.
Thank You,
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:BF67C18C-AEEC-408D-9185-86D4B5DC0772@.microsoft.com...
> Daniel, I am not sure if this can help in any ways but you might want to
have
> a quick look at it:
> Article: Setting the Default Process Security Level Using VBScript
> Link:
>
http://msdn.microsoft.com/library/de...v bscript.asp[vbcol=seagreen]
>
> Sasan
> "Daniel Gard" wrote:
very[vbcol=seagreen]
process[vbcol=seagreen]
same[vbcol=seagreen]
account?[vbcol=seagreen]
certificate.[vbcol=seagreen]
process[vbcol=seagreen]
run[vbcol=seagreen]
XML[vbcol=seagreen]
vbs[vbcol=seagreen]
in[vbcol=seagreen]
the[vbcol=seagreen]
proxy[vbcol=seagreen]
proxy[vbcol=seagreen]
was[vbcol=seagreen]
the[vbcol=seagreen]
in[vbcol=seagreen]
SQL[vbcol=seagreen]
message[vbcol=seagreen]
have a[vbcol=seagreen]
a[vbcol=seagreen]
updates[vbcol=seagreen]
notify[vbcol=seagreen]
been in[vbcol=seagreen]
was[vbcol=seagreen]
the[vbcol=seagreen]
tables[vbcol=seagreen]
this[vbcol=seagreen]
changed[vbcol=seagreen]
a[vbcol=seagreen]
to[vbcol=seagreen]
information.[vbcol=seagreen]
currently[vbcol=seagreen]
seems[vbcol=seagreen]
when[vbcol=seagreen]
know[vbcol=seagreen]
the[vbcol=seagreen]
We[vbcol=seagreen]
should.[vbcol=seagreen]

call to xp_cmdshell from trigger problem

To any SQL Server MVP:
We have a problem that out group can not seem to resolve. We have a
database that is used to alert and calculate required amounts of assistance
to clients that monitor through a private frame relay WAN. When a problem
occurs client 1 enters the request at a workstation which updates the
database and causes a trigger to fire and starts a process to notify the
other clients that assistance is required. This portion has been in use for
several years but now need to send information to a control area system,
rather than single entity, that is in XML format so a program was created to
take the data and format in accordance to the XML Schema rules the area
used.
At first it failed because the trigger called the EXE but the tables were
locked by the first program called in the trigger. To resolve this and
allow the trigger to continue thus unlocking the tables we changed the
trigger to call a vbs script file rather than the EXE directly. This seemed
to resolve the situation with locked tables in the database but a new issue
has come up I can not figure out.
The EXE has to use a X509 digital certificate to pass the data to the
client's server. When I run the EXE from the command line it works, when I
use SQL Query Manager and run the trigger code (less the alert portion) it
works but when the trigger fires is fails to send the information. It builds
everything but the client never gets the XML stream? We currently use
simple text files to track where the program process is but this file
indicates it finishes properly and all cleanup of objects occurs (Code in
VB6 and we use WinHTTP Request Object 5.1). The code has been altered to
indicate within the text file who started the program and this indicates the
"SQLProxy" account is who is running the EXE file. It almost seems that when
impersonate process occurs the local server does not treat the SQLProxy
account as the right one?
How can we test using SQL Query Manager the exact process as when the
trigger is fired from SQL Server?
Information:
ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called from
the trigger by the application user. This is what we created as instructed
by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
works because the first step in the trigger works.
CERTIFICATE: We logged on to the server using SQLProxy so the
certificate could be installed into the "My" store for the user. We could
move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.Hi Daniel,
I am just wondering under what user you did your test on query analyzer.
Have you tried the following to see what kind of result you get:
1. log in on the server by using your SQLProxy
2. Open query analyzer and connect to the server with Windows Authentication
3. try a test and see if the client gets the required info.
Sasan Saidi
Senior DBA
"Daniel Gard" wrote:
> To any SQL Server MVP:
> We have a problem that out group can not seem to resolve. We have a
> database that is used to alert and calculate required amounts of assistance
> to clients that monitor through a private frame relay WAN. When a problem
> occurs client 1 enters the request at a workstation which updates the
> database and causes a trigger to fire and starts a process to notify the
> other clients that assistance is required. This portion has been in use for
> several years but now need to send information to a control area system,
> rather than single entity, that is in XML format so a program was created to
> take the data and format in accordance to the XML Schema rules the area
> used.
> At first it failed because the trigger called the EXE but the tables were
> locked by the first program called in the trigger. To resolve this and
> allow the trigger to continue thus unlocking the tables we changed the
> trigger to call a vbs script file rather than the EXE directly. This seemed
> to resolve the situation with locked tables in the database but a new issue
> has come up I can not figure out.
> The EXE has to use a X509 digital certificate to pass the data to the
> client's server. When I run the EXE from the command line it works, when I
> use SQL Query Manager and run the trigger code (less the alert portion) it
> works but when the trigger fires is fails to send the information. It builds
> everything but the client never gets the XML stream? We currently use
> simple text files to track where the program process is but this file
> indicates it finishes properly and all cleanup of objects occurs (Code in
> VB6 and we use WinHTTP Request Object 5.1). The code has been altered to
> indicate within the text file who started the program and this indicates the
> "SQLProxy" account is who is running the EXE file. It almost seems that when
> impersonate process occurs the local server does not treat the SQLProxy
> account as the right one?
> How can we test using SQL Query Manager the exact process as when the
> trigger is fired from SQL Server?
>
> Information:
> ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called from
> the trigger by the application user. This is what we created as instructed
> by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
> works because the first step in the trigger works.
> CERTIFICATE: We logged on to the server using SQLProxy so the
> certificate could be installed into the "My" store for the user. We could
> move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
>
>
>
>
>|||Sasan
We have tried all of the following:
1. Logged on to the Windows server as the Domain Administrator and
connecting to SQL Server using windows authentication.
2. Logged on to the Windows server as the SQLProxy Account and connecting
to SQL Server using windows authentication.
We did notice is logged on to the Windows server as either 1 or 2 and
logging onto the SQL Server as the application user it does not work.
Thanks
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> Hi Daniel,
> I am just wondering under what user you did your test on query analyzer.
> Have you tried the following to see what kind of result you get:
> 1. log in on the server by using your SQLProxy
> 2. Open query analyzer and connect to the server with Windows
Authentication
> 3. try a test and see if the client gets the required info.
> Sasan Saidi
> Senior DBA
> "Daniel Gard" wrote:
> > To any SQL Server MVP:
> >
> > We have a problem that out group can not seem to resolve. We have a
> > database that is used to alert and calculate required amounts of
assistance
> > to clients that monitor through a private frame relay WAN. When a
problem
> > occurs client 1 enters the request at a workstation which updates the
> > database and causes a trigger to fire and starts a process to notify the
> > other clients that assistance is required. This portion has been in use
for
> > several years but now need to send information to a control area system,
> > rather than single entity, that is in XML format so a program was
created to
> > take the data and format in accordance to the XML Schema rules the area
> > used.
> >
> > At first it failed because the trigger called the EXE but the tables
were
> > locked by the first program called in the trigger. To resolve this and
> > allow the trigger to continue thus unlocking the tables we changed the
> > trigger to call a vbs script file rather than the EXE directly. This
seemed
> > to resolve the situation with locked tables in the database but a new
issue
> > has come up I can not figure out.
> >
> > The EXE has to use a X509 digital certificate to pass the data to the
> > client's server. When I run the EXE from the command line it works,
when I
> > use SQL Query Manager and run the trigger code (less the alert portion)
it
> > works but when the trigger fires is fails to send the information. It
builds
> > everything but the client never gets the XML stream? We currently use
> > simple text files to track where the program process is but this file
> > indicates it finishes properly and all cleanup of objects occurs (Code
in
> > VB6 and we use WinHTTP Request Object 5.1). The code has been altered
to
> > indicate within the text file who started the program and this indicates
the
> > "SQLProxy" account is who is running the EXE file. It almost seems that
when
> > impersonate process occurs the local server does not treat the SQLProxy
> > account as the right one?
> >
> > How can we test using SQL Query Manager the exact process as when the
> > trigger is fired from SQL Server?
> >
> >
> > Information:
> >
> > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called
from
> > the trigger by the application user. This is what we created as
instructed
> > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
> > works because the first step in the trigger works.
> >
> > CERTIFICATE: We logged on to the server using SQLProxy so the
> > certificate could be installed into the "My" store for the user. We
could
> > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
> >
> >
> >
> >
> >
> >
> >
> >
> >|||Sasan
The application user is a SQL Server account and not a Windows user account.
We noticed the following behavior. If the application user account was
placed into the SQL System Administrator group the program runsa as the
Domain account for the SQL Server and if this user is not a in the
administrator group then the program runs as SQLProxy.
The more I mess with this the more I think the user running the application
after the call from SQL Server can not find the digital certificate in the
CURRENT_USER\My store. How does the impersonation really work with SQL
Server?
Thanks
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> Hi Daniel,
> I am just wondering under what user you did your test on query analyzer.
> Have you tried the following to see what kind of result you get:
> 1. log in on the server by using your SQLProxy
> 2. Open query analyzer and connect to the server with Windows
Authentication
> 3. try a test and see if the client gets the required info.
> Sasan Saidi
> Senior DBA
> "Daniel Gard" wrote:
> > To any SQL Server MVP:
> >
> > We have a problem that out group can not seem to resolve. We have a
> > database that is used to alert and calculate required amounts of
assistance
> > to clients that monitor through a private frame relay WAN. When a
problem
> > occurs client 1 enters the request at a workstation which updates the
> > database and causes a trigger to fire and starts a process to notify the
> > other clients that assistance is required. This portion has been in use
for
> > several years but now need to send information to a control area system,
> > rather than single entity, that is in XML format so a program was
created to
> > take the data and format in accordance to the XML Schema rules the area
> > used.
> >
> > At first it failed because the trigger called the EXE but the tables
were
> > locked by the first program called in the trigger. To resolve this and
> > allow the trigger to continue thus unlocking the tables we changed the
> > trigger to call a vbs script file rather than the EXE directly. This
seemed
> > to resolve the situation with locked tables in the database but a new
issue
> > has come up I can not figure out.
> >
> > The EXE has to use a X509 digital certificate to pass the data to the
> > client's server. When I run the EXE from the command line it works,
when I
> > use SQL Query Manager and run the trigger code (less the alert portion)
it
> > works but when the trigger fires is fails to send the information. It
builds
> > everything but the client never gets the XML stream? We currently use
> > simple text files to track where the program process is but this file
> > indicates it finishes properly and all cleanup of objects occurs (Code
in
> > VB6 and we use WinHTTP Request Object 5.1). The code has been altered
to
> > indicate within the text file who started the program and this indicates
the
> > "SQLProxy" account is who is running the EXE file. It almost seems that
when
> > impersonate process occurs the local server does not treat the SQLProxy
> > account as the right one?
> >
> > How can we test using SQL Query Manager the exact process as when the
> > trigger is fired from SQL Server?
> >
> >
> > Information:
> >
> > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called
from
> > the trigger by the application user. This is what we created as
instructed
> > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
> > works because the first step in the trigger works.
> >
> > CERTIFICATE: We logged on to the server using SQLProxy so the
> > certificate could be installed into the "My" store for the user. We
could
> > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
> >
> >
> >
> >
> >
> >
> >
> >
> >|||When xp_cmdshell is invoked by a user who is a member of the sysadmin fixed
server role, xp_cmdshell will be executed under the security context in which
the SQL Server service is running. When the user is not a member of the
sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy
account, which is specified using xp_sqlagent_proxy_account. If the proxy
account is not available, xp_cmdshell will fail.
Sasan
"Daniel Gard" wrote:
> Sasan
> The application user is a SQL Server account and not a Windows user account.
> We noticed the following behavior. If the application user account was
> placed into the SQL System Administrator group the program runsa as the
> Domain account for the SQL Server and if this user is not a in the
> administrator group then the program runs as SQLProxy.
> The more I mess with this the more I think the user running the application
> after the call from SQL Server can not find the digital certificate in the
> CURRENT_USER\My store. How does the impersonation really work with SQL
> Server?
> Thanks
> Dan
>
> "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> > Hi Daniel,
> >
> > I am just wondering under what user you did your test on query analyzer.
> >
> > Have you tried the following to see what kind of result you get:
> > 1. log in on the server by using your SQLProxy
> > 2. Open query analyzer and connect to the server with Windows
> Authentication
> > 3. try a test and see if the client gets the required info.
> >
> > Sasan Saidi
> > Senior DBA
> >
> > "Daniel Gard" wrote:
> >
> > > To any SQL Server MVP:
> > >
> > > We have a problem that out group can not seem to resolve. We have a
> > > database that is used to alert and calculate required amounts of
> assistance
> > > to clients that monitor through a private frame relay WAN. When a
> problem
> > > occurs client 1 enters the request at a workstation which updates the
> > > database and causes a trigger to fire and starts a process to notify the
> > > other clients that assistance is required. This portion has been in use
> for
> > > several years but now need to send information to a control area system,
> > > rather than single entity, that is in XML format so a program was
> created to
> > > take the data and format in accordance to the XML Schema rules the area
> > > used.
> > >
> > > At first it failed because the trigger called the EXE but the tables
> were
> > > locked by the first program called in the trigger. To resolve this and
> > > allow the trigger to continue thus unlocking the tables we changed the
> > > trigger to call a vbs script file rather than the EXE directly. This
> seemed
> > > to resolve the situation with locked tables in the database but a new
> issue
> > > has come up I can not figure out.
> > >
> > > The EXE has to use a X509 digital certificate to pass the data to the
> > > client's server. When I run the EXE from the command line it works,
> when I
> > > use SQL Query Manager and run the trigger code (less the alert portion)
> it
> > > works but when the trigger fires is fails to send the information. It
> builds
> > > everything but the client never gets the XML stream? We currently use
> > > simple text files to track where the program process is but this file
> > > indicates it finishes properly and all cleanup of objects occurs (Code
> in
> > > VB6 and we use WinHTTP Request Object 5.1). The code has been altered
> to
> > > indicate within the text file who started the program and this indicates
> the
> > > "SQLProxy" account is who is running the EXE file. It almost seems that
> when
> > > impersonate process occurs the local server does not treat the SQLProxy
> > > account as the right one?
> > >
> > > How can we test using SQL Query Manager the exact process as when the
> > > trigger is fired from SQL Server?
> > >
> > >
> > > Information:
> > >
> > > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be called
> from
> > > the trigger by the application user. This is what we created as
> instructed
> > > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know it
> > > works because the first step in the trigger works.
> > >
> > > CERTIFICATE: We logged on to the server using SQLProxy so the
> > > certificate could be installed into the "My" store for the user. We
> could
> > > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
>
>|||Sasan
I understand that and we have all of this working. The problem seems very
strange even in my book because I am not sure if the impersonation process
uses a modified SID from the one if you log on the the server using the same
account. Does it take the domain user and create a temporary local account?
If so then that is the problem and this user can not find the certificate.
We are going to try to use a public certificate store and see if the process
will complete.
The program we wrote runs no matter what method the difference is when run
from the command line or from SQL Query manager it finishes by sending XML
to the the client but if the same process runs from being called by the vbs
script that is called by the trigger the client get nothing.
Thanks
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:7C116F51-C3BB-4ADD-96FC-9231D90287BE@.microsoft.com...
> When xp_cmdshell is invoked by a user who is a member of the sysadmin
fixed
> server role, xp_cmdshell will be executed under the security context in
which
> the SQL Server service is running. When the user is not a member of the
> sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy
> account, which is specified using xp_sqlagent_proxy_account. If the proxy
> account is not available, xp_cmdshell will fail.
> Sasan
> "Daniel Gard" wrote:
> > Sasan
> >
> > The application user is a SQL Server account and not a Windows user
account.
> > We noticed the following behavior. If the application user account was
> > placed into the SQL System Administrator group the program runsa as the
> > Domain account for the SQL Server and if this user is not a in the
> > administrator group then the program runs as SQLProxy.
> >
> > The more I mess with this the more I think the user running the
application
> > after the call from SQL Server can not find the digital certificate in
the
> > CURRENT_USER\My store. How does the impersonation really work with SQL
> > Server?
> >
> > Thanks
> > Dan
> >
> >
> > "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> > news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> > > Hi Daniel,
> > >
> > > I am just wondering under what user you did your test on query
analyzer.
> > >
> > > Have you tried the following to see what kind of result you get:
> > > 1. log in on the server by using your SQLProxy
> > > 2. Open query analyzer and connect to the server with Windows
> > Authentication
> > > 3. try a test and see if the client gets the required info.
> > >
> > > Sasan Saidi
> > > Senior DBA
> > >
> > > "Daniel Gard" wrote:
> > >
> > > > To any SQL Server MVP:
> > > >
> > > > We have a problem that out group can not seem to resolve. We have a
> > > > database that is used to alert and calculate required amounts of
> > assistance
> > > > to clients that monitor through a private frame relay WAN. When a
> > problem
> > > > occurs client 1 enters the request at a workstation which updates
the
> > > > database and causes a trigger to fire and starts a process to notify
the
> > > > other clients that assistance is required. This portion has been in
use
> > for
> > > > several years but now need to send information to a control area
system,
> > > > rather than single entity, that is in XML format so a program was
> > created to
> > > > take the data and format in accordance to the XML Schema rules the
area
> > > > used.
> > > >
> > > > At first it failed because the trigger called the EXE but the tables
> > were
> > > > locked by the first program called in the trigger. To resolve this
and
> > > > allow the trigger to continue thus unlocking the tables we changed
the
> > > > trigger to call a vbs script file rather than the EXE directly.
This
> > seemed
> > > > to resolve the situation with locked tables in the database but a
new
> > issue
> > > > has come up I can not figure out.
> > > >
> > > > The EXE has to use a X509 digital certificate to pass the data to
the
> > > > client's server. When I run the EXE from the command line it
works,
> > when I
> > > > use SQL Query Manager and run the trigger code (less the alert
portion)
> > it
> > > > works but when the trigger fires is fails to send the information.
It
> > builds
> > > > everything but the client never gets the XML stream? We currently
use
> > > > simple text files to track where the program process is but this
file
> > > > indicates it finishes properly and all cleanup of objects occurs
(Code
> > in
> > > > VB6 and we use WinHTTP Request Object 5.1). The code has been
altered
> > to
> > > > indicate within the text file who started the program and this
indicates
> > the
> > > > "SQLProxy" account is who is running the EXE file. It almost seems
that
> > when
> > > > impersonate process occurs the local server does not treat the
SQLProxy
> > > > account as the right one?
> > > >
> > > > How can we test using SQL Query Manager the exact process as when
the
> > > > trigger is fired from SQL Server?
> > > >
> > > >
> > > > Information:
> > > >
> > > > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be
called
> > from
> > > > the trigger by the application user. This is what we created as
> > instructed
> > > > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know
it
> > > > works because the first step in the trigger works.
> > > >
> > > > CERTIFICATE: We logged on to the server using SQLProxy so the
> > > > certificate could be installed into the "My" store for the user. We
> > could
> > > > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> >
> >
> >|||Daniel, I am not sure if this can help in any ways but you might want to have
a quick look at it:
Article: Setting the Default Process Security Level Using VBScript
Link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/setting_the_default_process_security_level_using_vbscript.asp
Sasan
"Daniel Gard" wrote:
> Sasan
> I understand that and we have all of this working. The problem seems very
> strange even in my book because I am not sure if the impersonation process
> uses a modified SID from the one if you log on the the server using the same
> account. Does it take the domain user and create a temporary local account?
> If so then that is the problem and this user can not find the certificate.
> We are going to try to use a public certificate store and see if the process
> will complete.
> The program we wrote runs no matter what method the difference is when run
> from the command line or from SQL Query manager it finishes by sending XML
> to the the client but if the same process runs from being called by the vbs
> script that is called by the trigger the client get nothing.
> Thanks
> "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> news:7C116F51-C3BB-4ADD-96FC-9231D90287BE@.microsoft.com...
> > When xp_cmdshell is invoked by a user who is a member of the sysadmin
> fixed
> > server role, xp_cmdshell will be executed under the security context in
> which
> > the SQL Server service is running. When the user is not a member of the
> > sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy
> > account, which is specified using xp_sqlagent_proxy_account. If the proxy
> > account is not available, xp_cmdshell will fail.
> >
> > Sasan
> >
> > "Daniel Gard" wrote:
> >
> > > Sasan
> > >
> > > The application user is a SQL Server account and not a Windows user
> account.
> > > We noticed the following behavior. If the application user account was
> > > placed into the SQL System Administrator group the program runsa as the
> > > Domain account for the SQL Server and if this user is not a in the
> > > administrator group then the program runs as SQLProxy.
> > >
> > > The more I mess with this the more I think the user running the
> application
> > > after the call from SQL Server can not find the digital certificate in
> the
> > > CURRENT_USER\My store. How does the impersonation really work with SQL
> > > Server?
> > >
> > > Thanks
> > > Dan
> > >
> > >
> > > "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> > > news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> > > > Hi Daniel,
> > > >
> > > > I am just wondering under what user you did your test on query
> analyzer.
> > > >
> > > > Have you tried the following to see what kind of result you get:
> > > > 1. log in on the server by using your SQLProxy
> > > > 2. Open query analyzer and connect to the server with Windows
> > > Authentication
> > > > 3. try a test and see if the client gets the required info.
> > > >
> > > > Sasan Saidi
> > > > Senior DBA
> > > >
> > > > "Daniel Gard" wrote:
> > > >
> > > > > To any SQL Server MVP:
> > > > >
> > > > > We have a problem that out group can not seem to resolve. We have a
> > > > > database that is used to alert and calculate required amounts of
> > > assistance
> > > > > to clients that monitor through a private frame relay WAN. When a
> > > problem
> > > > > occurs client 1 enters the request at a workstation which updates
> the
> > > > > database and causes a trigger to fire and starts a process to notify
> the
> > > > > other clients that assistance is required. This portion has been in
> use
> > > for
> > > > > several years but now need to send information to a control area
> system,
> > > > > rather than single entity, that is in XML format so a program was
> > > created to
> > > > > take the data and format in accordance to the XML Schema rules the
> area
> > > > > used.
> > > > >
> > > > > At first it failed because the trigger called the EXE but the tables
> > > were
> > > > > locked by the first program called in the trigger. To resolve this
> and
> > > > > allow the trigger to continue thus unlocking the tables we changed
> the
> > > > > trigger to call a vbs script file rather than the EXE directly.
> This
> > > seemed
> > > > > to resolve the situation with locked tables in the database but a
> new
> > > issue
> > > > > has come up I can not figure out.
> > > > >
> > > > > The EXE has to use a X509 digital certificate to pass the data to
> the
> > > > > client's server. When I run the EXE from the command line it
> works,
> > > when I
> > > > > use SQL Query Manager and run the trigger code (less the alert
> portion)
> > > it
> > > > > works but when the trigger fires is fails to send the information.
> It
> > > builds
> > > > > everything but the client never gets the XML stream? We currently
> use
> > > > > simple text files to track where the program process is but this
> file
> > > > > indicates it finishes properly and all cleanup of objects occurs
> (Code
> > > in
> > > > > VB6 and we use WinHTTP Request Object 5.1). The code has been
> altered
> > > to
> > > > > indicate within the text file who started the program and this
> indicates
> > > the
> > > > > "SQLProxy" account is who is running the EXE file. It almost seems
> that
> > > when
> > > > > impersonate process occurs the local server does not treat the
> SQLProxy
> > > > > account as the right one?
> > > > >
> > > > > How can we test using SQL Query Manager the exact process as when
> the
> > > > > trigger is fired from SQL Server?
> > > > >
> > > > >
> > > > > Information:
> > > > >
> > > > > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be
> called
> > > from
> > > > > the trigger by the application user. This is what we created as
> > > instructed
> > > > > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we know
> it
> > > > > works because the first step in the trigger works.
> > > > >
> > > > > CERTIFICATE: We logged on to the server using SQLProxy so the
> > > > > certificate could be installed into the "My" store for the user. We
> > > could
> > > > > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we should.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > >
> > >
> > >
>
>|||Sasan,
I'll look this over maybe there is something we missed in the vbs script
being called by the trigger.
Thank You,
Dan
"Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
news:BF67C18C-AEEC-408D-9185-86D4B5DC0772@.microsoft.com...
> Daniel, I am not sure if this can help in any ways but you might want to
have
> a quick look at it:
> Article: Setting the Default Process Security Level Using VBScript
> Link:
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/setting_the_default_process_security_level_using_vbscript.asp
>
> Sasan
> "Daniel Gard" wrote:
> > Sasan
> >
> > I understand that and we have all of this working. The problem seems
very
> > strange even in my book because I am not sure if the impersonation
process
> > uses a modified SID from the one if you log on the the server using the
same
> > account. Does it take the domain user and create a temporary local
account?
> > If so then that is the problem and this user can not find the
certificate.
> >
> > We are going to try to use a public certificate store and see if the
process
> > will complete.
> >
> > The program we wrote runs no matter what method the difference is when
run
> > from the command line or from SQL Query manager it finishes by sending
XML
> > to the the client but if the same process runs from being called by the
vbs
> > script that is called by the trigger the client get nothing.
> >
> > Thanks
> >
> > "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in message
> > news:7C116F51-C3BB-4ADD-96FC-9231D90287BE@.microsoft.com...
> > > When xp_cmdshell is invoked by a user who is a member of the sysadmin
> > fixed
> > > server role, xp_cmdshell will be executed under the security context
in
> > which
> > > the SQL Server service is running. When the user is not a member of
the
> > > sysadmin group, xp_cmdshell will impersonate the SQL Server Agent
proxy
> > > account, which is specified using xp_sqlagent_proxy_account. If the
proxy
> > > account is not available, xp_cmdshell will fail.
> > >
> > > Sasan
> > >
> > > "Daniel Gard" wrote:
> > >
> > > > Sasan
> > > >
> > > > The application user is a SQL Server account and not a Windows user
> > account.
> > > > We noticed the following behavior. If the application user account
was
> > > > placed into the SQL System Administrator group the program runsa as
the
> > > > Domain account for the SQL Server and if this user is not a in the
> > > > administrator group then the program runs as SQLProxy.
> > > >
> > > > The more I mess with this the more I think the user running the
> > application
> > > > after the call from SQL Server can not find the digital certificate
in
> > the
> > > > CURRENT_USER\My store. How does the impersonation really work with
SQL
> > > > Server?
> > > >
> > > > Thanks
> > > > Dan
> > > >
> > > >
> > > > "Sasan Saidi" <SasanSaidi@.discussions.microsoft.com> wrote in
message
> > > > news:A3A3E257-2889-4C54-BB23-05B4B352F696@.microsoft.com...
> > > > > Hi Daniel,
> > > > >
> > > > > I am just wondering under what user you did your test on query
> > analyzer.
> > > > >
> > > > > Have you tried the following to see what kind of result you get:
> > > > > 1. log in on the server by using your SQLProxy
> > > > > 2. Open query analyzer and connect to the server with Windows
> > > > Authentication
> > > > > 3. try a test and see if the client gets the required info.
> > > > >
> > > > > Sasan Saidi
> > > > > Senior DBA
> > > > >
> > > > > "Daniel Gard" wrote:
> > > > >
> > > > > > To any SQL Server MVP:
> > > > > >
> > > > > > We have a problem that out group can not seem to resolve. We
have a
> > > > > > database that is used to alert and calculate required amounts of
> > > > assistance
> > > > > > to clients that monitor through a private frame relay WAN. When
a
> > > > problem
> > > > > > occurs client 1 enters the request at a workstation which
updates
> > the
> > > > > > database and causes a trigger to fire and starts a process to
notify
> > the
> > > > > > other clients that assistance is required. This portion has
been in
> > use
> > > > for
> > > > > > several years but now need to send information to a control area
> > system,
> > > > > > rather than single entity, that is in XML format so a program
was
> > > > created to
> > > > > > take the data and format in accordance to the XML Schema rules
the
> > area
> > > > > > used.
> > > > > >
> > > > > > At first it failed because the trigger called the EXE but the
tables
> > > > were
> > > > > > locked by the first program called in the trigger. To resolve
this
> > and
> > > > > > allow the trigger to continue thus unlocking the tables we
changed
> > the
> > > > > > trigger to call a vbs script file rather than the EXE directly.
> > This
> > > > seemed
> > > > > > to resolve the situation with locked tables in the database but
a
> > new
> > > > issue
> > > > > > has come up I can not figure out.
> > > > > >
> > > > > > The EXE has to use a X509 digital certificate to pass the data
to
> > the
> > > > > > client's server. When I run the EXE from the command line it
> > works,
> > > > when I
> > > > > > use SQL Query Manager and run the trigger code (less the alert
> > portion)
> > > > it
> > > > > > works but when the trigger fires is fails to send the
information.
> > It
> > > > builds
> > > > > > everything but the client never gets the XML stream? We
currently
> > use
> > > > > > simple text files to track where the program process is but this
> > file
> > > > > > indicates it finishes properly and all cleanup of objects occurs
> > (Code
> > > > in
> > > > > > VB6 and we use WinHTTP Request Object 5.1). The code has been
> > altered
> > > > to
> > > > > > indicate within the text file who started the program and this
> > indicates
> > > > the
> > > > > > "SQLProxy" account is who is running the EXE file. It almost
seems
> > that
> > > > when
> > > > > > impersonate process occurs the local server does not treat the
> > SQLProxy
> > > > > > account as the right one?
> > > > > >
> > > > > > How can we test using SQL Query Manager the exact process as
when
> > the
> > > > > > trigger is fired from SQL Server?
> > > > > >
> > > > > >
> > > > > > Information:
> > > > > >
> > > > > > ACCOUNT: SQLProxy is a domain account so xp_cmdshell can be
> > called
> > > > from
> > > > > > the trigger by the application user. This is what we created as
> > > > instructed
> > > > > > by SQLAgentCmdExec rules using xp_sqlagent_proxy_account and we
know
> > it
> > > > > > works because the first step in the trigger works.
> > > > > >
> > > > > > CERTIFICATE: We logged on to the server using SQLProxy so
the
> > > > > > certificate could be installed into the "My" store for the user.
We
> > > > could
> > > > > > move it to HKEY_LOCAL_MACHINE\Trusted People if you think we
should.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> >
> >
> >