.NET Framework - Is SQL 2000 tran working with VS2008?
Asked By aspfun via DotNetMonster.com
05-Feb-10 09:15 PM
I code a store procedure mySP in SQL 2000 in which using transaction.
I used two ways to test after saving sp.
1) rename one table
or
2) rename column name
If I use "exec mySP" in SQL 2000 query window, error will catch but ASP.NET
try-catch will catch nothing, it always return no error.
Is SQL 2000 tran working with VS2008?
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
SQL Server 2000
(1)
MySQLCommand.ExecuteNonQuery
(1)
ConfigurationManager.AppSettings
(1)
CommandType.StoredProcedure
(1)
MySQLCommand.CommandType
(1)
SqlDbType
(1)
ExecuteNonQuery
(1)
SqlConnection
(1)
Alexey Smirnov replied to aspfun via DotNetMonster.com
ET
ms.aspx/asp-net/201002/1
Are you sure that you execute SP from ASP.NET, does it work when table
is not renamed?
aspfun via DotNetMonster.com replied to Alexey Smirnov
Yes, I try to figure out the problem for two days but no luck.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
Mark Rae [MVP] replied to aspfun via DotNetMonster.com
Please show your code.
Also, FYI, SQL Server 2000 has not been supported by Microsoft for nearly
two years unless you have taken out an extended support contract:
http://support.microsoft.com/lifecycle/search/default.aspx?sort=PN&alpha=SQL+Server+2000&Filter=FilterNO
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
aspfun via DotNetMonster.com replied to Mark Rae [MVP]
Here is the code copied from
http://www.4guysfromrolla.com/webtech/080305-1.shtml
In asp.net code behind, I use try-catch try to catch any error but never
catch it.
In SQL database, if I rename Employees to Employeesx or change column
DepartmentID to DepartmentIDx, record will not be deleted (it is right)
without any error (it is wrong, suppose catch an error).
CREATE PROCEDURE DeleteDepartment
(
@DepartmentID int
)
AS
BEGIN TRANSACTION
DELETE FROM Employees
WHERE DepartmentID = @DepartmentID
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error', 16, 1)
RETURN
END
DELETE FROM Departments
WHERE DepartmentID = @DepartmentID
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error', 16, 1)
RETURN
END
OMMIT
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
Mr. Arnold replied to aspfun via DotNetMonster.com
Well, you would 'return' @@ERROR as an Output parm from the sproc and
check the Output Error code in your code that called the sproc.
If Output Return code <> 0, then the sproc aborted.
You should look-up how to return an output parm from a SQL Server Stored
Procedure.
So, on one hand, you have try/catch looking for SQL exception, but on
the other hand, you are looking at the Output Parm Error code. If Output
Parm Error code = 0, then ok, else terminate program.
Mark Rae [MVP] replied to aspfun via DotNetMonster.com
That's great, but now please show your code...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
aspfun via DotNetMonster.com replied to Mark Rae [MVP]
I did use output parameter as set @myerror = @@error.
In ASP.NET catch block, @myerror is cought but always = 0 no matter how to
test, such as rename table or rename column name. (both tests should return
@myerror <> 0 but not)
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
Mr. Arnold replied to aspfun via DotNetMonster.com
Well, if any T-SQL statement is executed after the error and the
statement is successful, then @@error is going to equal 0. Each T-SQL
statement that is successfully executed after the error is going to
override what ever was in @@error when the error occurred.
The error was not critical enough to throw a SQL exception, and the
sproc executed other T-SQL statements after the error, which resulted in
@@error being set to 0.
It does not seem you are trapping the @@error at the right time possibly.
Alexey Smirnov replied to aspfun via DotNetMonster.com
e
y
..
1.shtml
ms.aspx/asp-net/201002/1
Here is the code that works
SqlConnection conn =3D null;
try
{
conn =3D new SqlConnection("....");
conn.Open();
SqlCommand cmd =3D new SqlCommand("DeleteDepartment",
conn);
SqlParameter p =3D new SqlParameter("@DepartmentID",
xxx);
cmd.Parameters.Add(p);
cmd.CommandType =3D CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
finally
{
if (conn !=3D null)
{
conn.Close();
}
}
Tested against SQL Server 2000 - 8.00.2187 (x86) Enterprise Edition
(Build 2195: Service Pack 4)
Hope this helps
aspfun via DotNetMonster.com replied to Alexey Smirnov
Thank you. I will test it.
I just check sql server in our company, they are only have sp2 installed.
(sp4 is available for a long time). Is it cause problem of not catching error?
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
Alexey Smirnov replied to aspfun via DotNetMonster.com
able
orums.aspx/asp-net/201002/1
eDepartment",
partmentID",
ocedure;
rror?
ms.aspx/asp-net/201002/1
Well, I do not think that this is a server issue. I think your code was
wrong
aspfun via DotNetMonster.com replied to Alexey Smirnov
I checked my code, it is the same as yours.
Protected Function Test(ByVal _id As Integer) As Boolean
Dim myDSN As String = ConfigurationManager.AppSettings("ConnectionString")
//get connection from web.config
Dim myConn As New SqlConnection(myDSN)
Dim mySQLCommand As New SqlCommand("sSQLTransation", myConn)
mySQLCommand.CommandType = CommandType.StoredProcedure
Dim prmid As New SqlParameter("@DepartmentID", SqlDbType.Int, 4)
prmid.Value = _id
mySQLCommand.Parameters.Add(prmid)
Using myConn
Try
myConn.Open()
mySQLCommand.ExecuteNonQuery()
myConn.Close()
Return True
Catch ex As SqlException
Me.lblMessagebar.Text = ex.Message
Return False
Finally
If myConn IsNot Nothing Then
myConn.Close()
End If
End Try
End Using
End Function
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201002/1
Mr. Arnold replied to Alexey Smirnov
Hear! Hear! ADO.NET and SQL server have been around a long time for it
to be a SQL server issue.
The OP is doing something wrong in code.
Alexey Smirnov replied to aspfun via DotNetMonster.com
n table
orums.aspx/asp-net/201002/1
There are few things in your code where it might be wrong.
1) sSQLTransation is not the same stored procedure
2) check if ConfigurationManager.AppSettings("ConnectionString")
returns correct database
3) check if lblMessagebar is visible and you do not change its text
after calling the Test() function
It must be something in the code. Try to simplify it as much as
possible (for example, create a test page where you run only one
function and see what happens)
Hope this helps.
Is Linq to SQL any good? .NET Framework I am a big fan of linq but in my opinion linq to sql is a complete waste of time. Why on earth take something that is already complex (sql) and make it more complex and difficult to write by creating a translation layer. I see people here struggling to write linq to sql queries. It also creates the problem of being locked into a particular product with regards as generally in newsgroups on those who disagree reply. :-) Thanks in advance, Michael C# Discussions SQL Server 6.5 (1) SQL Server (1) Windows Communication Foundation (1) MySQL (1) Entity Framework (1) Visual Studio (1) Silverlight (1
View timed out every now and then .NET Framework We are using SQL Server 2005 and VB.NET 2008. We have a view that is called by the application SELECT of 2 more views and a table. When I run the view on the SQL Server Management Studio, it runs for 2 seconds. Most of the time when the view is error "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.), even after I set the command time out to 45 seconds (which view runs fast most of the time, but very slow once or twice a day ? SQL Server machine has 8 processors of 2993 Mhz each and 32 MB of RAM. Right now the available physical memory there is 18.48 GB, and SQL Server is using 9-50% of CPU and 11, 358, 080K of RAM. It has
Timeout expired. The timeout period elapsed prior to completion ofthe operation or the server is not responding. .NET Framework Our application is in VB.NET 2008 and our database is SQL Server 2005. Our application runs on Windows Server 2003 R2 Standard Edition SP 2. The database runs on Windows Server 2003 R2 Enterprise x64 Edition SP 1. The database server has many databases. The database connection string in the program uses a name instance, not error "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." What would cause this error to show up every now and then myID;Password = myPwd;Max Pool Size = 200" .Open() End With Thank you VB.NET Discussions SQL Server 2005 (1) SQL Server 2000 (1) Windows Server 2003 R2 (1) SQL Server Books
VB 2010 Express - Wie komme ich in eine SQL-DB ? .NET Framework Ich habe probehalber mal VB2010 Express installiert. Wenn ich eine neue Datenquelle erdstellen will, wird aber nur SQL compacht, Access-DB und SQL Datenbankdatei, nicht aber ein SQL-Server angeboten. Wie kann ich dieses Feature nachinstallieren ? P.S: Ich habe die CD von SQL2008 den ClientTools scheint es aber nicht getan zu sein. Gruss Nico VB.NET - German Discussions SQL Server 2008 (1) SQL Express (1) SQL Server (1) Oracle (1) St.Georgen (1) VB (1) DB (1) SQLserver
UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView2.ItemInserting Dim student As Integer Dim comd As SqlCommand Dim sql, id As String ' check amount of student for project 'A' in table 'student' Using mConnection As New SqlConnection(param.ConnectionString) mConnection.Open() sql = "select count(*) from student where id = @id" comd = New SqlCommand sql, mConnection) comd.Parameters.AddWithValue("@id", 'A') student = comd.ExecuteScalar mConnection.Close() End Using If student WebControls.DetailsViewInsertedEventArgs) Handles DetailsView2.ItemInserted Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), End Sub ASP.NET Discussions SQL Server (1) DetailsViewInsertedEventArgs (1) DetailsViewInsertEventArgs (1) SQL Server Books Online (1) RegisterClientScriptBlock (1) Page (1) Stored procedure (1) SqlConnection (1) There is nothing But the trigger would protect you if those naughty students try you out. - - Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http: / / msdn