473,387 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

code is not inserting row into database

3
hello, pls help look through this code its not inserting the record in dataset into the another database.
i want to insert the row in the dataset into another table in another database.
pls help. it urgent i submit this application. when it runs it gives: this OdbcTransaction has completed,it no longer usable.
thx
toyin
here is the code

Sub ProcessAllSynchOperations()
Dim sSourceURL, sWebSiteIP As String
Dim dLastUpdate As DateTime
Dim iLoop As Integer
' iterate through all the URLs in the config file
For iLoop = 0 To gSourceURLArray.Length - 1
' get values for this source site
sSourceURL = gSourceURLArray(iLoop).Trim()
WriteStatus("Processing " & sSourceURL)
sWebSiteIP = gSiteIPArray(iLoop).Trim()
WriteStatus("Row key value is " & sWebSiteIP)
dLastUpdate = GetLastDateLoaded(sWebSiteIP)
Application.DoEvents()
' call routine to fetch the DataSet from the remote Web Service
Dim oDS As DataSet = FetchTables(sSourceURL, sWebSiteIP, gTableNames, dLastUpdate)
' see if there were any errors with the Web Service
If oDS Is Nothing Then
Throw New Exception("No DataSet returned from Web Service")
End If
If oDS.Tables(0).TableName = "Errors" Then
Throw New Exception("Error reported by Web Service: " & oDS.Tables(0).Rows(0)(0))
End If
Dim oConn As OdbcConnection
Dim oTrans As OdbcTransaction

Try
' create Connection, open it and start a transaction
oConn = New OdbcConnection(gConnStr)
oConn.Open()
oTrans = oConn.BeginTransaction()
' iterate through all the tables in the list
Dim sTableName As String
For Each sTableName In gTableArray
Application.DoEvents()
If gbCancel = True Then
Throw New Exception("Process canceled by user.")
End If
' check if table is in DataSet - might not be if there were no new rows
If oDS.Tables(sTableName) Is Nothing Then
WriteStatus(">> WARNING: no rows received for table '" & sTableName & "'")
Else
' see how many rows are in this table
Dim iRows As Integer = oDS.Tables(sTableName).Rows.Count
WriteStatus("Received " & iRows.ToString() & " rows.")
If iRows > 0 Then
WriteStatus("Updating database...")
Application.DoEvents()
Try
' create new Command for SelectCommand within current transaction
Dim oSCmd As New OdbcCommand("SELECT * FROM " & sTableName, oConn, oTrans)
' create DataAdapter from Command
Dim oDA As New OdbcDataAdapter(oSCmd)
' create auto-generated INSERT command with CommandBuilder
Dim oCB As New OdbcCommandBuilder(oDA)
' get InsertCommand from CommandBuilder
Dim oICmd As OdbcCommand = oCB.GetInsertCommand()
' attach the current transaction to the InsertCommand
oICmd.Transaction = oTrans
' specify this as the InsertCommand of the DataAdapter
oDA.InsertCommand = oICmd
' update the database table
Dim iCount As Integer = oDA.Update(oDS, sTableName)
WriteStatus("Added " & iCount.ToString() & " rows to table '" & sTableName & "'")
Application.DoEvents()
Catch e As Exception
oTrans.Rollback()
Throw New Exception("Error updating target table " & sTableName & " - " & e.Message)
End Try
End If
End If
Next
' all OK so commit all of the updates
oTrans.Commit()
WriteStatus("Transaction committed" & vbCrLf)
Catch e As Exception
' error encountered so roll back all the updates
oTrans.Rollback()
Throw New Exception("Transaction failed to complete - " & e.Message)
Finally
oConn.Close()
End Try
' update last synchronization date file for this site
UpdateLastDateLoaded(sWebSiteIP)
Next
end sub

Sub GetConfigurationValues()
' get values from application configuration file
gConnStr = ConfigurationSettings.AppSettings("TargetOdbcConne ctionString")
gTableNames = ConfigurationSettings.AppSettings("SourceTableList ")
Dim sSourceUrl As String = ConfigurationSettings.AppSettings("SourceWebServic eURL")
Dim sWebSiteIP As String = ConfigurationSettings.AppSettings("SourceDatabaseA ddresses")
' check that the required values exist
If sSourceUrl = String.Empty Or gConnStr = String.Empty _
Or sWebSiteIP = String.Empty Or gTableNames = String.Empty Then
Throw New Exception("Error loading configuration settings from " & System.Reflection.Assembly.GetExecutingAssembly.Lo cation & ".config")
Else
' display values on Form
SourceWS.Text = "Source Web Service URLs: " & sSourceUrl
WebSiteIP.Text = "Source Web Site IP Addresses: " & sWebSiteIP
TargetConn.Text = "Target Database Connection String: " & gConnStr
gSourceURLArray = sSourceUrl.Split(",")
gSiteIPArray = sWebSiteIP.Split(",")
If gSourceURLArray.Length <> gSiteIPArray.Length Then
Throw New Exception("There are a different number of Web Service URLs and IP addresses in the configuration file")
End If
gTableArray = gTableNames.Split(",")
Application.DoEvents()
End If
End Sub

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="SourceWebServiceURL"
value="http://localhost/SynDatabase/GetNewRecord.asmx"/>

<add key="SourceDatabaseAddresses"
value="PROVIDER={MSDASQL.1};DSN=myodbc;SERVER =localhost;DATABASE =db1;UID =root;PWD = webserver;port=3306" />

<add key="TargetOdbcConnectionString"
value="PROVIDER=MSDASQL.1;DSN=myodbc1;server=local host;database=db2;uid=root;pwd=webserver" />

<add key="SourceTableList"
value="table2" />

<add key="LogFileFullPathAndName"
value="c:\inetpub\wwwroot\synchiis.inc" />
</appSettings>
</configuration>
Oct 22 '07 #1
0 2200

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising...
13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
1
by: Scott Chapman | last post by:
I am working with Python (psycopg). I have HTML with embedded Python that I'm inserting into a database and it could contain any character. Single quotes, at least, must be escaped (to two...
1
by: ram achar | last post by:
please send me C# code for inserting values into database sql server2005 *** Sent via Developersdex http://www.developersdex.com ***
3
by: veerapureddy | last post by:
Hai everybody, i like to insert some records into database from html form by entering data.my problem is how can i check , whether a record is available in database about a particular...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
2
by: Ravigandha | last post by:
Hello everybody, My question is how to insert special characters and symbols in Mysql5 database and how to retrieve them from database in php. Here i am inserting some data from a form,by post...
9
by: Bunty | last post by:
I am not beginer of this language. I've worked on this language for 2 or 3 months.But now i have a problem to inserting values in the database.It gives me error that DATABASE NOT SELECTED. I am...
6
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.