Showing posts with label anasp. Show all posts
Showing posts with label anasp. Show all posts

Monday, March 26, 2012

Oh those Transaction Headaches!

Hi all!

Perhaps a wise soul can help me here. I have an insert routine for an
ASP.Net application and it works fine, but I decided to test the transaction
rollback capabilities by stopping the SQL server when it was just about to
insert the record (I use a breakpoint and then stop the server). What should
have happened is that the transaction is rolled back and my catch block
response.writes the error which would be something about the network
connection.

Unfortunately, within the catch block when it tries to rollback the
transaction I get another error which states

This SqlTransaction has completed; it is no longer usable

Here is the general look of my code

' *** Use SQL commands to directly insert info into DataSource

Dim strConnection As String

Dim objConnection As SqlConnection

Dim objCommand As New SqlCommand()

Dim objTransaction As SqlTransaction

objConnection = New SqlConnection(Application("strConnection"))

Try

objConnection.Open()

objTransaction = objConnection.BeginTransaction()

' *** Create the Command and set its properties

objCommand.Connection = objConnection

objCommand.Transaction = objTransaction

objCommand.CommandText = "sp_LogInsert2"

objCommand.CommandType = CommandType.StoredProcedure

' Set the various Parameters for the stored Procedure

Blah, Blah, Blah

objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
executes this line

objTransaction.Commit()

Catch objError As Exception

'Error was encountered so roll back all the inserts

objTransaction.Rollback()

' Display error details

Response.write("**** Error while inserting data ****" +
objError.Message + "<br/>" + objError.Source)

Finally

objConnection.Close()

End Try

For some reason many people tell me it has to do with the Try block. Wrox
Professional ASP.Net has many examples of having the BeginTransaction within
the Try block. But just for the sake of argument I moved the Open Connection
and the Begin Transaction outside of the try block. No difference was seen.

Could someone please tell me what I am doing wrong?

DanoI think this is not an ASP.NET question.

The error is telling you, that the transaction is completed. You cannot
rollback (or commit) a transaction that is already complete. It's done.

"Dano" <dtemple7502@.rogers.com> wrote in message
news:P19ub.459$FkK1.315@.twister01.bloor.is.net.cab le.rogers.com...
> Hi all!
> Perhaps a wise soul can help me here. I have an insert routine for an
> ASP.Net application and it works fine, but I decided to test the
transaction
> rollback capabilities by stopping the SQL server when it was just about to
> insert the record (I use a breakpoint and then stop the server). What
should
> have happened is that the transaction is rolled back and my catch block
> response.writes the error which would be something about the network
> connection.
> Unfortunately, within the catch block when it tries to rollback the
> transaction I get another error which states
> This SqlTransaction has completed; it is no longer usable
>
> Here is the general look of my code
>
> ' *** Use SQL commands to directly insert info into DataSource
> Dim strConnection As String
> Dim objConnection As SqlConnection
> Dim objCommand As New SqlCommand()
> Dim objTransaction As SqlTransaction
>
> objConnection = New SqlConnection(Application("strConnection"))
> Try
>
> objConnection.Open()
> objTransaction = objConnection.BeginTransaction()
>
> ' *** Create the Command and set its properties
> objCommand.Connection = objConnection
> objCommand.Transaction = objTransaction
> objCommand.CommandText = "sp_LogInsert2"
>
> objCommand.CommandType = CommandType.StoredProcedure
>
> ' Set the various Parameters for the stored Procedure
> Blah, Blah, Blah
>
> objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
> executes this line
> objTransaction.Commit()
> Catch objError As Exception
>
> 'Error was encountered so roll back all the inserts
> objTransaction.Rollback()
>
> ' Display error details
> Response.write("**** Error while inserting data ****" +
> objError.Message + "<br/>" + objError.Source)
>
> Finally
> objConnection.Close()
> End Try
>
> For some reason many people tell me it has to do with the Try block. Wrox
> Professional ASP.Net has many examples of having the BeginTransaction
within
> the Try block. But just for the sake of argument I moved the Open
Connection
> and the Begin Transaction outside of the try block. No difference was
seen.
> Could someone please tell me what I am doing wrong?
> Dano
you cannot roll the transaction back because you lost the connection and
there is no way to notify sqlserver to rollback (it will on its own). there
are other cases when rollbacks will fail, such as when the transaction did a
rollback on its own.

-- bruce (sqlwork.com)

"Dano" <dtemple7502@.rogers.com> wrote in message
news:P19ub.459$FkK1.315@.twister01.bloor.is.net.cab le.rogers.com...
> Hi all!
> Perhaps a wise soul can help me here. I have an insert routine for an
> ASP.Net application and it works fine, but I decided to test the
transaction
> rollback capabilities by stopping the SQL server when it was just about to
> insert the record (I use a breakpoint and then stop the server). What
should
> have happened is that the transaction is rolled back and my catch block
> response.writes the error which would be something about the network
> connection.
> Unfortunately, within the catch block when it tries to rollback the
> transaction I get another error which states
> This SqlTransaction has completed; it is no longer usable
>
> Here is the general look of my code
>
> ' *** Use SQL commands to directly insert info into DataSource
> Dim strConnection As String
> Dim objConnection As SqlConnection
> Dim objCommand As New SqlCommand()
> Dim objTransaction As SqlTransaction
>
> objConnection = New SqlConnection(Application("strConnection"))
> Try
>
> objConnection.Open()
> objTransaction = objConnection.BeginTransaction()
>
> ' *** Create the Command and set its properties
> objCommand.Connection = objConnection
> objCommand.Transaction = objTransaction
> objCommand.CommandText = "sp_LogInsert2"
>
> objCommand.CommandType = CommandType.StoredProcedure
>
> ' Set the various Parameters for the stored Procedure
> Blah, Blah, Blah
>
> objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
> executes this line
> objTransaction.Commit()
> Catch objError As Exception
>
> 'Error was encountered so roll back all the inserts
> objTransaction.Rollback()
>
> ' Display error details
> Response.write("**** Error while inserting data ****" +
> objError.Message + "<br/>" + objError.Source)
>
> Finally
> objConnection.Close()
> End Try
>
> For some reason many people tell me it has to do with the Try block. Wrox
> Professional ASP.Net has many examples of having the BeginTransaction
within
> the Try block. But just for the sake of argument I moved the Open
Connection
> and the Begin Transaction outside of the try block. No difference was
seen.
> Could someone please tell me what I am doing wrong?
> Dano

Saturday, March 24, 2012

OLAP and ASP.NET

I am working on Analysis Services. We are developing an
ASP.NET application which will access data from OLAP
Cubes. creation of OLAP Cube is done.

I am not able to access the same from asp.net. Can someone
please help me ? How do i access OLAP Cube in ASP.NET
applcation??

are there any custom controls or code examples plz help
urgent...these is no direct mdx support in .net. you have to use the OleDbReader
(with lastest sp), or create interop wrappers for the mdx com objects

-- bruce (sqlwork.com)

"Melroy" <melroy_britto@.hotmail.com> wrote in message
news:2cc2401c39400$86e8a410$a601280a@.phx.gbl...
> I am working on Analysis Services. We are developing an
> ASP.NET application which will access data from OLAP
> Cubes. creation of OLAP Cube is done.
> I am not able to access the same from asp.net. Can someone
> please help me ? How do i access OLAP Cube in ASP.NET
> applcation??
> are there any custom controls or code examples plz help
> urgent...

Old Dos Program from asp.net website

I have a requirement to execute a legacy DOS program from within an
ASP.NET Website. I have it working in my sandbox machine but when I
put it live and select the option via asp:button the site simply
refreshes and no new window with said DOS application appears. The
application is present in the task list on the server. The
environement is windows 2003 with IIS 6.0. I have checked the 'Allow
serviec to interact with desktop' check box in the IIS Admin services
and have modified the machine.config process model tag to
<processModel userName="SYSTEM" password="AutoGenerate" /as per the
msdn article 'Unable to Start a Process from ASP.NET' (not sure that
is exactly what I should put). I have tried to modify the IIS_WPG
group to allow system privileges and even assigned it adminstrator
rights for a bit to see if that did anything. I have also played
around with the ASPNET account in IIS and gave in admin privileges to
see if that does anything. I added the process code that starts the
app below but since I see it in the task list I assume that is good.
I can't think of anything else I can do any help would be appreciated.

System.Diagnostics.Process cmd = new System.Diagnostics.Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
bool started = cmd.Start();
if (started)
{
Button btn = (Button)sender;
string arg1 = btn.CommandArgument.ToString();
cmd.StandardInput.WriteLine(@dotnet.itags.org."D:\wincmd\TotalCmd.exe",
arg1);
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
}"wmotter" <wmotter@.prolist.comwrote in message
news:1189698723.321670.180540@.g4g2000hsf.googlegro ups.com...

Quote:

Originally Posted by

I have a requirement to execute a legacy DOS program from within an
ASP.NET Website. I have it working in my sandbox machine


What are you actually expecting to happen here...?

Presumably, your sandbox machine is the one at which you're sitting while
you're developing...?

Quote:

Originally Posted by

System.Diagnostics.Process cmd = new System.Diagnostics.Process();


Which will try to run on the webserver, not a client machine...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
On Sep 13, 12:11 pm, "Mark Rae [MVP]" <m...@.markNOSPAMrae.netwrote:

Quote:

Originally Posted by

"wmotter" <wmot...@.prolist.comwrote in message
>
news:1189698723.321670.180540@.g4g2000hsf.googlegro ups.com...
>

Quote:

Originally Posted by

I have a requirement to execute a legacy DOS program from within an
ASP.NET Website. I have it working in my sandbox machine


>
What are you actually expecting to happen here...?
>
Presumably, your sandbox machine is the one at which you're sitting while
you're developing...?
>

Quote:

Originally Posted by

System.Diagnostics.Process cmd = new System.Diagnostics.Process();


>
Which will try to run on the webserver, not a client machine...
>
--
Mark Rae
ASP.NET MVPhttp://www.markrae.net


Thanks for the response. I am running my website local (localhost on
the 'sandbox' machine) using IIS 5.0 and what happens is a second
window pops with the dos application executing when I select a button
on the asp.net website. You have raised an issue I am unsure about
and that is running a DOS app from an asp.net web site. Can I execute
a dos app on the web server from an asp.net website so that an
individual can view/use it from their client machine. I would think
there might be something inherently prohibited about this from a
security standpoint but maybe that is why I need to jump through all
of these permission hoops. BTW, I log on as sys admin to the web
server that is running the live site in question and try to execute
this scenario to no avail. This server is an internal server not
accessible outside of the office.
"wmotter" <wmotter@.prolist.comwrote in message
news:1189703475.238000.23400@.w3g2000hsg.googlegrou ps.com...

Quote:

Originally Posted by

Thanks for the response. I am running my website local (localhost on
the 'sandbox' machine)


That's what I thought...

Quote:

Originally Posted by

Can I execute a dos app on the web server from an asp.net website...


Yes.

...so that an individual can view/use it from their client machine.

No.

Quote:

Originally Posted by

I would think there might be something inherently prohibited about this
from a security standpoint but maybe that is why I need to jump through
all
of these permission hoops.


It's nothing to do with security - it's simply that ASP.NET is running on
the server, and that's where any processes which ASP.NET initiates will
run...

Quote:

Originally Posted by

BTW, I log on as sys admin to the web server that is running the live site
in
question and try to execute this scenario to no avail.


That won't make any difference.

Quote:

Originally Posted by

This server is an internal server not accessible outside of the office.


Irrelevant...

What does this DOS app do? Why does someone need to watch it run...?

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
re:
!...so that an individual can view/use it from their client machine.

!No.

The standard output (stdout) could be captured and displayed, couldn't it ?

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message news:%23vGF%23qi9HHA.5424@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

"wmotter" <wmotter@.prolist.comwrote in message news:1189703475.238000.23400@.w3g2000hsg.googlegrou ps.com...
>

Quote:

Originally Posted by

>Thanks for the response. I am running my website local (localhost on
>the 'sandbox' machine)


>
That's what I thought...
>

Quote:

Originally Posted by

>Can I execute a dos app on the web server from an asp.net website...


>
Yes.
>
...so that an individual can view/use it from their client machine.
>
No.
>

Quote:

Originally Posted by

>I would think there might be something inherently prohibited about this
>from a security standpoint but maybe that is why I need to jump through all
>of these permission hoops.


>
It's nothing to do with security - it's simply that ASP.NET is running on the server, and that's where any processes
which ASP.NET initiates will run...
>

Quote:

Originally Posted by

>BTW, I log on as sys admin to the web server that is running the live site in
>question and try to execute this scenario to no avail.


>
That won't make any difference.
>

Quote:

Originally Posted by

>This server is an internal server not accessible outside of the office.


>
Irrelevant...
>
What does this DOS app do? Why does someone need to watch it run...?
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message
news:u9Nuiyi9HHA.1416@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

re:
!...so that an individual can view/use it from their client machine.
>
!No.
>
The standard output (stdout) could be captured and displayed, couldn't it
?


Oh sure, but I got the impression that the OP needs to have user interaction
with the DOS app...

Obviously if that's not the case, then this will present no problem at
all...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
re:
!Oh sure, but I got the impression that the OP
!needs to have user interaction with the DOS app...

That won't happen, as you well know...

;-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
======================================
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message news:%23Duqm8i9HHA.5316@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

"Juan T. Llibre" <nomailreplies@.nowhere.comwrote in message news:u9Nuiyi9HHA.1416@.TK2MSFTNGP03.phx.gbl...
>

Quote:

Originally Posted by

>re:
>!...so that an individual can view/use it from their client machine.
>>
>!No.
>>
>The standard output (stdout) could be captured and displayed, couldn't it ?


>
Oh sure, but I got the impression that the OP needs to have user interaction with the DOS app...
>
Obviously if that's not the case, then this will present no problem at all...
>
>
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


"wmotter" <wmotter@.prolist.comwrote in message
news:1189706106.858456.44480@.50g2000hsm.googlegrou ps.com...

Quote:

Originally Posted by

The DOS app needs to be local on each machine that is going to use it
(not a problem since it is an interanl app).


Ah...

Quote:

Originally Posted by

But the question remains can a web app start a local copy of a DOS app
with .net?


Absolutely not natively, for fairly obvious security reasons - "format c:"
is a useful utility, but you wouldn't want a website to be able to execute
it on client machines... :-)

Your only hope with this is to write an ActiveX control (or Java applet if
you're not using IE) which will kick the DOS app off, but you'll need to
ramp down your browser security for this...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
"Mark Rae [MVP]" <mark@.markNOSPAMrae.netwrote in message
news:eoThiFj9HHA.1204@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Your only hope with this is to write an ActiveX control (or Java applet if
you're not using IE) which will kick the DOS app off, but you'll need to
ramp down your browser security for this...


Or you might be able to use the WSH (Windows Scripting Host) Shell object to
launch it:
http://www.pcsupportadvisor.com/Win..._host_page2.htm
--
Mark Rae
ASP.NET MVP
http://www.markrae.net