public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* SQL server utility not working when invoked(from a asp.net application) using cygwin
@ 2014-03-24 10:36 Afreen..
  2014-03-24 10:43 ` Chris J. Breisch
  0 siblings, 1 reply; 8+ messages in thread
From: Afreen.. @ 2014-03-24 10:36 UTC (permalink / raw)
  To: cygwin

Hello,

I have an asp.net application which uses cygwin to execute shell
scripts in Windows environment. sqlcmd utility is used in these shell
scripts to connect to a database and execute queries. sqlcmd is
command line application that allows SQL queries to be written and
executed from the command prompt.

The sqlcmd utility works fine when directly invoked from the .net
application or when the script is directly executed at the Cygwin
terminal. But fails on integration ie. when the application creates a
cygwin process & executes the script (I'm using cygwin bash.exe to do
this) ,sqlcmd utility fails.

To start a cygwin process,using a piece of code similar to this:

{
string FileName= @"c:\cygwin\bin\bash.exe";
string Arguments= @"C:\MyDir\Test.script";
ProcessStartInfo proc = ProcessStartInfo(FileName,Arguments);
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
Process P = new Process();
P.StartInfo=proc;
P.Start();
P.WaitForExit();
}


Here Test.script is the script which contains the sqlcmd
command.Output of the command is redirected to a file.

sqlcmd -U abc -P abc -S MyServer -Q "sp_helpuser abc" > sql.log

Is there something wrong with the way I'm creating the process (using
bash.exe) or calling the script?How do I invoke cygwin and execute my
script from an asp.net application?

Using .net framework 4.0 and cygwin 1.7.20.
Any help will be highly appreciated!Thanks in advance!


-- 
Regards,
Afreen T

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
  2014-03-24 10:36 SQL server utility not working when invoked(from a asp.net application) using cygwin Afreen..
@ 2014-03-24 10:43 ` Chris J. Breisch
  2014-03-24 19:26   ` Chris J. Breisch
  0 siblings, 1 reply; 8+ messages in thread
From: Chris J. Breisch @ 2014-03-24 10:43 UTC (permalink / raw)
  To: cygwin

Afreen.. wrote:
> Hello,
>
> I have an asp.net application which uses cygwin to execute shell
> scripts in Windows environment. sqlcmd utility is used in these shell
> scripts to connect to a database and execute queries. sqlcmd is
> command line application that allows SQL queries to be written and
> executed from the command prompt.
>
> The sqlcmd utility works fine when directly invoked from the .net
> application or when the script is directly executed at the Cygwin
> terminal. But fails on integration ie. when the application creates a
> cygwin process&  executes the script (I'm using cygwin bash.exe to do
> this) ,sqlcmd utility fails.
>
> To start a cygwin process,using a piece of code similar to this:
>
> {
> string FileName= @"c:\cygwin\bin\bash.exe";
> string Arguments= @"C:\MyDir\Test.script";
> ProcessStartInfo proc = ProcessStartInfo(FileName,Arguments);
> proc.UseShellExecute = false;
> proc.CreateNoWindow = true;
> Process P = new Process();
> P.StartInfo=proc;
> P.Start();
> P.WaitForExit();
> }
>
>
> Here Test.script is the script which contains the sqlcmd
> command.Output of the command is redirected to a file.
>
> sqlcmd -U abc -P abc -S MyServer -Q "sp_helpuser abc">  sql.log
>
> Is there something wrong with the way I'm creating the process (using
> bash.exe) or calling the script?How do I invoke cygwin and execute my
> script from an asp.net application?
>
> Using .net framework 4.0 and cygwin 1.7.20.
> Any help will be highly appreciated!Thanks in advance!
>
>

Can you give more specifics on how it fails? And is it possible for you 
to upgrade to a more recent version of Cygwin? I'm doing almost all of 
this except for the ASP.net part, and I have no problems. I do this at 
work, and I'm not at the office right now. It's possible I quote the 
arguments differently. I can check in the morning. I also use Windows 
authentication and not SQL authentication, but that shouldn't matter. In 
fact, of the two, SQL authentication is the way less likely to cause issues.

-- 
Chris J. Breisch

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
  2014-03-24 10:43 ` Chris J. Breisch
@ 2014-03-24 19:26   ` Chris J. Breisch
  2014-03-25  2:10     ` Chris J. Breisch
  0 siblings, 1 reply; 8+ messages in thread
From: Chris J. Breisch @ 2014-03-24 19:26 UTC (permalink / raw)
  To: cygwin

Chris J. Breisch wrote:
>
> Can you give more specifics on how it fails? And is it possible for you
> to upgrade to a more recent version of Cygwin? I'm doing almost all of
> this except for the ASP.net part, and I have no problems. I do this at
> work, and I'm not at the office right now. It's possible I quote the
> arguments differently. I can check in the morning. I also use Windows
> authentication and not SQL authentication, but that shouldn't matter. In
> fact, of the two, SQL authentication is the way less likely to cause
> issues.
>

I checked on what I'm doing in my script. Here's an exact line of code 
from my shell script:
    ${SQLCMD} -E -d ${_db} -S ${_server} -o ${_dosOutput} -Q "${_query}"

Where the variables are defined as follows:
SQLCMD="sqlcmd.exe"
_db=<database name>
_server=<server name>
_dosOutput=<output file name>
_query=<query string>

Note that I'm not using bash redirection, but the sqlcmd option to send 
output to a file. The -E tells sqlcmd to use Windows Authentication 
(actually it uses impersonation, which has it's own set of quirks, but 
that's not an issue for you), rather than using the -U and -P options as 
you are.

I did notice that in your original post you said -Q "sp_helpuser abc". I 
doubt that this is the problem, but -Q "exec sp_helpuser abc" is 
preferred. In my case, I'm not calling a stored procedure but passing an 
actual SQL select, insert, or update to sqlcmd. That shouldn't make any 
difference, though.

I also recently had a problem executing something with sqlcmd, as I 
mistyped "-S" as "-s". I didn't notice that tiny typo for hours and 
pulled out quite a bit of hair. Make sure the case is correct for all 
your options.

Without additional details on what is or isn't happening, this is as 
much assistance as I can provide.

-- 
Chris J. Breisch

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
  2014-03-24 19:26   ` Chris J. Breisch
@ 2014-03-25  2:10     ` Chris J. Breisch
  2014-03-25 14:12       ` Andrey Repin
  0 siblings, 1 reply; 8+ messages in thread
From: Chris J. Breisch @ 2014-03-25  2:10 UTC (permalink / raw)
  To: cygwin

Chris J. Breisch wrote:
> Without additional details on what is or isn't happening, this is as
> much assistance as I can provide.
>

I lied. I had one more thought.

Your username, password, database name, sql server name don't contain 
characters that are special to bash, do they? Of the four, password is 
the most likely.

But a password might contain any of ~!@#$%^&*()+`-{}[]|\:";'<>,.?/ or 
even <space>

Any of those could cause problems in your script if they're not properly 
quoted/escaped.

Hoping the filter doesn't eat this because of use of the p-word.

-- 
Chris J. Breisch

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
  2014-03-25  2:10     ` Chris J. Breisch
@ 2014-03-25 14:12       ` Andrey Repin
  2014-03-25 14:54         ` Chris J. Breisch
  0 siblings, 1 reply; 8+ messages in thread
From: Andrey Repin @ 2014-03-25 14:12 UTC (permalink / raw)
  To: Chris J. Breisch, cygwin

Greetings, Chris J. Breisch!

>> Without additional details on what is or isn't happening, this is as
>> much assistance as I can provide.
>>

> I lied. I had one more thought.

> Your username, password, database name, sql server name don't contain 
> characters that are special to bash, do they? Of the four, password is 
> the most likely.

_dosOutput is a more likely offender.
Because of backslashes. Since it's unquoted.

> But a password might contain any of ~!@#$%^&*()+`-{}[]|\:";'<>,.?/ or 
> even <space>

> Any of those could cause problems in your script if they're not properly 
> quoted/escaped.

> Hoping the filter doesn't eat this because of use of the p-word.



--
WBR,
Andrey Repin (anrdaemon@yandex.ru) 25.03.2014, <15:39>

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
  2014-03-25 14:12       ` Andrey Repin
@ 2014-03-25 14:54         ` Chris J. Breisch
  0 siblings, 0 replies; 8+ messages in thread
From: Chris J. Breisch @ 2014-03-25 14:54 UTC (permalink / raw)
  To: cygwin

Andrey Repin wrote:
> Greetings, Chris J. Breisch!
>
>>> Without additional details on what is or isn't happening, this is as
> _dosOutput is a more likely offender.
> Because of backslashes. Since it's unquoted.

No, that's from my example, which works, not his. I handle creation of 
the file name properly. But yes, quoting would be a good idea.

-- 
Chris J. Breisch

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
       [not found] ` <CAN=kAG6+ZE=d-J_4BYJdnPBbRBORX3je1OhPxbHcknKLFRtoCA@mail.gmail.com>
@ 2014-03-31  8:31   ` Afreen..
  0 siblings, 0 replies; 8+ messages in thread
From: Afreen.. @ 2014-03-31  8:31 UTC (permalink / raw)
  To: cygwin

Chris Breisch wrote:

>>Greetings, Chris J. Breisch!
>>Without additional details on what is or isn't happening, this is as
>>_dosOutput is a more likely offender.
>>Because of backslashes. Since it's unquoted.
>No, that's from my example, which works, not his. I handle creation of the file name properly. But yes, quoting would be a good idea.

Forgot to mention this in the mail i sent out a few minutes ago.The
output filename is quoted in my case.I'll check for special characters
in the password and try using one without those.Update you guys about
that.
Thanks again Chris & Andrey!

Regards,
Afreen T

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: SQL server utility not working when invoked(from a asp.net application) using cygwin
@ 2014-03-31  8:30 Afreen..
       [not found] ` <CAN=kAG6+ZE=d-J_4BYJdnPBbRBORX3je1OhPxbHcknKLFRtoCA@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Afreen.. @ 2014-03-31  8:30 UTC (permalink / raw)
  To: cygwin

Hi,

Thanks for the response Chris.Really appreciate the help.
Well,The return status for the sqlcmd command is 1. sqlcmd probably
just does not get executed.The query is not executed nor is the output
redirected to sql.log.It does not even give an error message if I pass
an incorrect parameter.

The same script (ie. Test.script here) & the sqlcmd command in it are
executed correctly when directly invoked from the cygwin terminal.

One more interesting thing here is that if I use the osql utility
(It's a sql server utility similar to sqlcmd) instead of sqlcmd in the
script,it works perfectly fine (even when the script is called from
the asp.net application).

Also, I'll upgrade to a more recent version of cygwin and check if it
solves the issue.


Thanks & Regards,
Afreen T

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-03-30 19:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 10:36 SQL server utility not working when invoked(from a asp.net application) using cygwin Afreen..
2014-03-24 10:43 ` Chris J. Breisch
2014-03-24 19:26   ` Chris J. Breisch
2014-03-25  2:10     ` Chris J. Breisch
2014-03-25 14:12       ` Andrey Repin
2014-03-25 14:54         ` Chris J. Breisch
2014-03-31  8:30 Afreen..
     [not found] ` <CAN=kAG6+ZE=d-J_4BYJdnPBbRBORX3je1OhPxbHcknKLFRtoCA@mail.gmail.com>
2014-03-31  8:31   ` Afreen..

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).