Link to home
Start Free TrialLog in
Avatar of evault
evaultFlag for United States of America

asked on

how can I actually commit changes to the SQL database programtically?

I have VB 2008 Express Edition with MS SQL Server 2005 Express Edition. I have used the built-in wizards in the VB environment to build a database, connect it to the program and insert, change and delete records. It even saved the records. However, after I modified the program a little (didn't do anything to automatically generated code that saves the records to the database), it quit saving the changes. It will save them as long as I don't quit the application, but once I commit the applciation the changes I made are no longer there. Any suggestions?
Avatar of chapmandew
chapmandew
Flag of United States of America image

You may have a transaction open and when you close out of the program the transaction rolls back.  Do you know what stored procedures your program is calling?  Is it using inline code in the program?
i think in proram ur using begin tran,rollabck tran,commit tran,
ur commit tran code is not working and rollback tran is working that why u r not able to  see change data.
if you are not executeing rollback tran then ur server speed continues down.
u can see it by sp_lock
Avatar of evault

ASKER

I am testing the coe and everytime I make a change I click on the save button (code attached) to commit the changes, then either modify znother record or add one. I do not believe I have any open transactions, however I am new to SQL server so I am not going to discount that. How d I tell if I have any open transactions? By the way, I have only the one table in the database, so far.

    Private Sub Tbl_WtyBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbl_WtyBindingNavigatorSaveItem.Click
        ' save items???
        Me.Validate()
        Me.Tbl_WtyBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.WtyDBDataSet)
    End Sub

Open in new window

In TSQL you can check the @@TRANCOUNT variable.  If it is > 0 then there are open transactions
Avatar of evault

ASKER

Thank you chapmandew, I will try thast this afternoon snd report back to you.
Avatar of evault

ASKER

chapmandew - How do I check that variable programmatically?
In the stored procedure (TSQL) you can do it like this


IF @@TRANCOUNT > 0
PRINT 'A transaction is still open'
ELSE
PRINT 'No transactions open'
Avatar of evault

ASKER

The language (VB Express 2008) Does not recognize the verb @@TRANCOUNT
That is true...you have to call a stored procedure in vb (using ADO or ADO.net) to use the TSQL code....
Avatar of evault

ASKER

Actually I found out what is going on. Wehn I process the Excell spreadsheets, pulling information out of them, the transaction won't save. Neither will it save when I cut or copy and paste into any of the fields that I am using on the user form. However, if I manually enter a vlaue into any field, by typing, then the record will save. Any idea on that?
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of evault

ASKER

Sorry about he delay, I'll try to be better. Which part of the code do you want?