insert stored procedure does not commit to the database More options

P

philhey

Hi,

I have a problem where an insert stored procedure does not commit to
the database from a vb.net program. I can run the stored procedure
fine through the IDE, but when I use the following vb code the
message
box shows the next ID number but when I check the database no new row
has been added. Any ideas?


Phil


*******STORED PROCEDURE


CREATE PROCEDURE MYSP_InsertEposTransaction
@TransactionDate AS DATETIME, @CustomerID AS Integer,
@TransactionTypeID AS Integer, @UserID AS Integer,
@PaymentTypeID AS Integer
AS
SET NOCOUNT ON
BEGIN TRAN
INSERT EposTransaction
(
TransactionDate,
CustomerID,
TransactionTypeID,
UserID,
PaymentTypeID
)
VALUES
(
@TransactionDate,
@CustomerID,
@TransactionTypeID,
@UserID,
@PaymentTypeID
)


RETURN SCOPE_IDENTITY()

COMMIT TRAN



*VB CODE


Dim conn As New SqlConnection()
conn.ConnectionString = "Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\EposTill.mdf;Integrated
Security=True;User Instance=True"


Dim cmd As New SqlCommand()
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "MYSP_InsertEposTransaction"


' Create a SqlParameter for each parameter in the stored
procedure.
Dim transDateParam As New SqlParameter("@TransactionDate",
Now())
Dim customerIDParam As New SqlParameter("@CustomerID", 1)
Dim transactionTypeParam As New
SqlParameter("@TransactionTypeID", 1)
Dim userIDParam As New SqlParameter("@UserID", 1)
Dim paymentTypeParam As New SqlParameter("@PaymentTypeID", 1)
cmd.Parameters.Add(transDateParam)
cmd.Parameters.Add(customerIDParam)
cmd.Parameters.Add(transactionTypeParam)
cmd.Parameters.Add(userIDParam)
cmd.Parameters.Add(paymentTypeParam)


Dim previousConnectionState As ConnectionState = conn.State
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
MsgBox(cmd.ExecuteScalar)
Finally
If previousConnectionState = ConnectionState.Closed Then
conn.Close()
End If
End Try
 
W

William \(Bill\) Vaughn

Okay, I suggest that you turn on the SQL Profiler and see what's getting
sent to the server for execution. This way you can see how (or if) the SP is
being executed.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
 
P

philhey

Thanks for the reply, I am using SQL Express and am not sure that it
comes with an SQL Profiler, I might have developer copy of SQL
Profiler for SQL Server 2000, will this work on a SQL Express server?

Thanks

Phil
 
R

Rad [Visual C# MVP]

Thanks for the reply, I am using SQL Express and am not sure that it
comes with an SQL Profiler, I might have developer copy of SQL
Profiler for SQL Server 2000, will this work on a SQL Express server?

Thanks

Phil

Not sure ... but if the worst comes to the worst you could do something
like raising an error in your procedure to check if it is indeed being
called at all
 
W

William \(Bill\) Vaughn

Then I suggest getting SQL Server 2005 Developer Edition (about $50) that
includes all of these tools. The SS 2000 Profiler might work though. Can't
say that I've tried it. If you're creating a serious application, then you
need the right tools.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top