Showing posts with label master. Show all posts
Showing posts with label master. Show all posts

Monday, March 26, 2012

question on using xp_cmdshell

I am trying to run an exe file like:

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe "input parameter"'

And executing the above with the input should give me an output.But the input parameter is not recognised. Any help.

Thanks

EXEC xp_cmdshell 'dir *.exe';

try removing the double quotes, above I do a DIR command passing in *.exe

|||Not recognized by whom? The test.exe command? What do you mean by input parameter. Can you post an actual example so we can try it?|||EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input_parameter'|||Did these replies solved your problem or not?|||

The test.exe is a tool to extract output when an input is given.

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input'

if i do like above i should be able to get the output.

Thanks

|||

kast wrote:

The test.exe is a tool to extract output when an input is given.

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input'

if i do like above i should be able to get the output.

Thanks

good, then mark a reply as the ANSWER.

Derek

|||

There is one problem still.

On the command prompt

I use as C:\folderA\folderB\test.exe "input" gives me the ouput desired.

When I do same thing in the query analyszer using xp_cmdshell as

EXEC master.dbo.xp_cmdshell 'C:\folderA\folderB\test.exe "input"'

it errors out saying

NULL
Error: c:\folderA\exam.cpp (100):Failed to open the key file
Error: c:\folderA\exam2.cpp (150):Invalid input
NULL

I checked and the relavant cpp files are in that path and also this error doesn't happen when i do in the cmd prompt directly.

Anything wrong with the xp_cmdshell syntax I have used?

Thanks

|||Does the key file exist on the path C:\folderA on the server? Note that the xp_cmdshell runs on the server so you need to copy all the necessary files for the EXEC to the corresponding directories on the server. There is nothing wrong with the xp_cmdshell syntax. The problem is in your environment / configuration.|||

One of two things are happening.

1. The files are not in the location expected

2. You have a security problem

When you execute it directly from a command line, the security context it will be running under is your Windows account and it will also be using the path statement set for your account to locate files.

When you execute this using xp_cmdshell, the security context the command is running under is the Windows account of the SQL Server service and also be using the path statement set for that account. The the SQL Server service account does not have the authority to open the key file this .exe is directly things through, then you are going to get this type of error.

|||

Hello

It seems like you are having a security issue here.

When you are using xp_cmdshell then you will "loose" your security context, and SQL Server will try to create a connection to the share with HIS security context. If you use a "Local Systemaccount" for SQL Server it wont be possible to access any network shares in your domain, since this account is "unknown" to the domain. So either move the file to a harddrive thats local to the SQL Server, or switch the SQL Server to use a domain account (I would prefer moving the file locally, since granting the SQL Server domain access would open attackers entry to your domain if they manage to compromise your SQL Server)

|||

EXEC master.dbo.xp_cmdshell 'C:\folderA\folderB\test.exe "input"'

Instead of doing as above I created a test.bat file as

cd\
cd folderA
cd folderB

Test.exe "input"

and then called it as

EXEC master.dbo.xp_cmdshell Test.bat "input"

This Worked.Thanks everyone for the effort.Thanks again.

|||

you may want to note that XPs are to no longer exist after SQL 2005 via this quote that is everywhere in BOL2005:

"This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use CLR Integration instead."

And regardless of xp_cmdShells future I would encourage you to port what your doing into the CLR as it is a much more safer and secure environment than xps. As a matter of fact in my upcoming book we have an entire chapter dedicated to the topic as porting XPs is one of the big reasons to employ the technology.

Derek

|||Thanks for the information.|||Please mark an answer

question on using xp_cmdshell

I am trying to run an exe file like:

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe "input parameter"'

And executing the above with the input should give me an output.But the input parameter is not recognised. Any help.

Thanks

EXEC xp_cmdshell 'dir *.exe';

try removing the double quotes, above I do a DIR command passing in *.exe

|||Not recognized by whom? The test.exe command? What do you mean by input parameter. Can you post an actual example so we can try it?|||EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input_parameter'|||Did these replies solved your problem or not?|||

The test.exe is a tool to extract output when an input is given.

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input'

if i do like above i should be able to get the output.

Thanks

|||

kast wrote:

The test.exe is a tool to extract output when an input is given.

EXEC master.dbo.xp_cmdshell '\\Share\sharepoint\folder1\folder2\test.exe input'

if i do like above i should be able to get the output.

Thanks

good, then mark a reply as the ANSWER.

Derek

|||

There is one problem still.

On the command prompt

I use as C:\folderA\folderB\test.exe "input" gives me the ouput desired.

When I do same thing in the query analyszer using xp_cmdshell as

EXEC master.dbo.xp_cmdshell 'C:\folderA\folderB\test.exe "input"'

it errors out saying

NULL
Error: c:\folderA\exam.cpp (100):Failed to open the key file
Error: c:\folderA\exam2.cpp (150):Invalid input
NULL

I checked and the relavant cpp files are in that path and also this error doesn't happen when i do in the cmd prompt directly.

Anything wrong with the xp_cmdshell syntax I have used?

Thanks

|||Does the key file exist on the path C:\folderA on the server? Note that the xp_cmdshell runs on the server so you need to copy all the necessary files for the EXEC to the corresponding directories on the server. There is nothing wrong with the xp_cmdshell syntax. The problem is in your environment / configuration.|||

One of two things are happening.

1. The files are not in the location expected

2. You have a security problem

When you execute it directly from a command line, the security context it will be running under is your Windows account and it will also be using the path statement set for your account to locate files.

When you execute this using xp_cmdshell, the security context the command is running under is the Windows account of the SQL Server service and also be using the path statement set for that account. The the SQL Server service account does not have the authority to open the key file this .exe is directly things through, then you are going to get this type of error.

|||

Hello

It seems like you are having a security issue here.

When you are using xp_cmdshell then you will "loose" your security context, and SQL Server will try to create a connection to the share with HIS security context. If you use a "Local Systemaccount" for SQL Server it wont be possible to access any network shares in your domain, since this account is "unknown" to the domain. So either move the file to a harddrive thats local to the SQL Server, or switch the SQL Server to use a domain account (I would prefer moving the file locally, since granting the SQL Server domain access would open attackers entry to your domain if they manage to compromise your SQL Server)

|||

EXEC master.dbo.xp_cmdshell 'C:\folderA\folderB\test.exe "input"'

Instead of doing as above I created a test.bat file as

cd\
cd folderA
cd folderB

Test.exe "input"

and then called it as

EXEC master.dbo.xp_cmdshell Test.bat "input"

This Worked.Thanks everyone for the effort.Thanks again.

|||

you may want to note that XPs are to no longer exist after SQL 2005 via this quote that is everywhere in BOL2005:

"This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use CLR Integration instead."

And regardless of xp_cmdShells future I would encourage you to port what your doing into the CLR as it is a much more safer and secure environment than xps. As a matter of fact in my upcoming book we have an entire chapter dedicated to the topic as porting XPs is one of the big reasons to employ the technology.

Derek

|||Thanks for the information.|||Please mark an answer

Monday, March 12, 2012

Question on ON DELETE CASCADE

I have a master table and a child table. I have created a foreignkey
constraint on the child table with OUT the ON DELETE CASCADE option.
Now when I delete records from the Master table, can I specify "on
delete cascade" at that time.
Or I can do that only if I specify when the foreign key is created.
Thanks in advance.Hi
> Or I can do that only if I specify when the foreign key is created.
Yes
"SQL novice" <balacr@.gmail.com> wrote in message
news:1132299915.134325.257320@.g44g2000cwa.googlegroups.com...
>I have a master table and a child table. I have created a foreignkey
> constraint on the child table with OUT the ON DELETE CASCADE option.
> Now when I delete records from the Master table, can I specify "on
> delete cascade" at that time.
> Or I can do that only if I specify when the foreign key is created.
> Thanks in advance.
>

Question on multiserver environment in SQL Server 2005

I am creating a backup strategy for our non-production SQL Server 2005 data. We wish to utiliza the Master/Target Server scenario avaible in SQL Server 2005 with events directed to the Master Server. The question I have is what is the symptoms from the Target Servers if the Master Server fails and is unavailable for whatever reason there might be? I can change the event notification back to local server, but what other impact is there and are there any recommendations as to handle a Master Server outage so Maintenance plans can continue to execute as scheduled on Target Servers.

Thank you!

Here's a response, but one that you won't like. Virtually nobody I know uses the Master/Target option. I am sure there must be some people who do, but it is rare. It is not used because the feature is not very robust or flexible.

Most people use a third-party monitoring program to accomplish what are want to do. There are many available. In addition, there are various third-party backup programs that include backup monitoring built-in.

Question on multiserver environment in SQL Server 2005

I am creating a backup strategy for our non-production SQL Server 2005 data. We wish to utiliza the Master/Target Server scenario avaible in SQL Server 2005 with events directed to the Master Server. The question I have is what is the symptoms from the Target Servers if the Master Server fails and is unavailable for whatever reason there might be? I can change the event notification back to local server, but what other impact is there and are there any recommendations as to handle a Master Server outage so Maintenance plans can continue to execute as scheduled on Target Servers.

Thank you!

Here's a response, but one that you won't like. Virtually nobody I know uses the Master/Target option. I am sure there must be some people who do, but it is rare. It is not used because the feature is not very robust or flexible.

Most people use a third-party monitoring program to accomplish what are want to do. There are many available. In addition, there are various third-party backup programs that include backup monitoring built-in.

Wednesday, March 7, 2012

Question on encryption/ keys/ certificates/ etc.

SQL2K5
SP1
I was able to sucessfully create a Master Key, create a Certificate, create
a Symmetric Key and assign it to the Certificate, insert encrypted data, and
then decrypt/ read that data. Pretty cool stuff. But Im reading up on the
topic and Im under the impression that I should also have needed too:
Set Force Encryption to Yes.
Configure the DB engine to use a Cert.
Reboot the box.
But I didn't have to do any of that. I just went and verified the settings
and thats not how SQL is configured. Im obviosuly missing something pretty
big here, can someone please assist?
TIA, ChrisRThat's 2 different things, what you've been doing is encrypting data stored
in the database. The other stuff you are talking about is encrypting traffic
from clients to SQL Server and vice versa. If you don't have that
requirement then don't worry about it. In SQL 2005, standard SQL logins are
encrypted anyway by a self generated certificate however general traffic
to/from the server (batches/results etc) are not. They are 2 completely
different and separate things.
HTH,
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
"ChrisR" <NotAChance@.ms.com> wrote in message
news:esEA%23%23AtGHA.1876@.TK2MSFTNGP06.phx.gbl...
> SQL2K5
> SP1
> I was able to sucessfully create a Master Key, create a Certificate,
> create
> a Symmetric Key and assign it to the Certificate, insert encrypted data,
> and
> then decrypt/ read that data. Pretty cool stuff. But Im reading up on the
> topic and Im under the impression that I should also have needed too:
> Set Force Encryption to Yes.
> Configure the DB engine to use a Cert.
> Reboot the box.
> But I didn't have to do any of that. I just went and verified the settings
> and thats not how SQL is configured. Im obviosuly missing something pretty
> big here, can someone please assist?
> TIA, ChrisR
>|||As mentioned, I was missing something pretty big. ;-)
Thanks Jasper.
"Jasper Smith" <jasper_smith9@.hotmail.com> wrote in message
news:eaL$0QCtGHA.4784@.TK2MSFTNGP04.phx.gbl...
> That's 2 different things, what you've been doing is encrypting data
stored
> in the database. The other stuff you are talking about is encrypting
traffic
> from clients to SQL Server and vice versa. If you don't have that
> requirement then don't worry about it. In SQL 2005, standard SQL logins
are
> encrypted anyway by a self generated certificate however general traffic
> to/from the server (batches/results etc) are not. They are 2 completely
> different and separate things.
> --
> HTH,
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
>
> "ChrisR" <NotAChance@.ms.com> wrote in message
> news:esEA%23%23AtGHA.1876@.TK2MSFTNGP06.phx.gbl...
the[vbcol=seagreen]
settings[vbcol=seagreen]
pretty[vbcol=seagreen]
>

Question on encryption/ keys/ certificates/ etc.

SQL2K5
SP1
I was able to sucessfully create a Master Key, create a Certificate, create
a Symmetric Key and assign it to the Certificate, insert encrypted data, and
then decrypt/ read that data. Pretty cool stuff. But Im reading up on the
topic and Im under the impression that I should also have needed too:
Set Force Encryption to Yes.
Configure the DB engine to use a Cert.
Reboot the box.
But I didn't have to do any of that. I just went and verified the settings
and thats not how SQL is configured. Im obviosuly missing something pretty
big here, can someone please assist?
TIA, ChrisRThat's 2 different things, what you've been doing is encrypting data stored
in the database. The other stuff you are talking about is encrypting traffic
from clients to SQL Server and vice versa. If you don't have that
requirement then don't worry about it. In SQL 2005, standard SQL logins are
encrypted anyway by a self generated certificate however general traffic
to/from the server (batches/results etc) are not. They are 2 completely
different and separate things.
--
HTH,
Jasper Smith (SQL Server MVP)
http://www.sqldbatips.com
"ChrisR" <NotAChance@.ms.com> wrote in message
news:esEA%23%23AtGHA.1876@.TK2MSFTNGP06.phx.gbl...
> SQL2K5
> SP1
> I was able to sucessfully create a Master Key, create a Certificate,
> create
> a Symmetric Key and assign it to the Certificate, insert encrypted data,
> and
> then decrypt/ read that data. Pretty cool stuff. But Im reading up on the
> topic and Im under the impression that I should also have needed too:
> Set Force Encryption to Yes.
> Configure the DB engine to use a Cert.
> Reboot the box.
> But I didn't have to do any of that. I just went and verified the settings
> and thats not how SQL is configured. Im obviosuly missing something pretty
> big here, can someone please assist?
> TIA, ChrisR
>|||As mentioned, I was missing something pretty big. ;-)
Thanks Jasper.
"Jasper Smith" <jasper_smith9@.hotmail.com> wrote in message
news:eaL$0QCtGHA.4784@.TK2MSFTNGP04.phx.gbl...
> That's 2 different things, what you've been doing is encrypting data
stored
> in the database. The other stuff you are talking about is encrypting
traffic
> from clients to SQL Server and vice versa. If you don't have that
> requirement then don't worry about it. In SQL 2005, standard SQL logins
are
> encrypted anyway by a self generated certificate however general traffic
> to/from the server (batches/results etc) are not. They are 2 completely
> different and separate things.
> --
> HTH,
> Jasper Smith (SQL Server MVP)
> http://www.sqldbatips.com
>
> "ChrisR" <NotAChance@.ms.com> wrote in message
> news:esEA%23%23AtGHA.1876@.TK2MSFTNGP06.phx.gbl...
> > SQL2K5
> > SP1
> >
> > I was able to sucessfully create a Master Key, create a Certificate,
> > create
> > a Symmetric Key and assign it to the Certificate, insert encrypted data,
> > and
> > then decrypt/ read that data. Pretty cool stuff. But Im reading up on
the
> > topic and Im under the impression that I should also have needed too:
> >
> > Set Force Encryption to Yes.
> > Configure the DB engine to use a Cert.
> > Reboot the box.
> >
> > But I didn't have to do any of that. I just went and verified the
settings
> > and thats not how SQL is configured. Im obviosuly missing something
pretty
> > big here, can someone please assist?
> >
> > TIA, ChrisR
> >
> >
>