Solved

manage remote MySQL transactions

Posted on 2011-09-22
7
370 Views
Last Modified: 2012-05-12
Experts -

New to MySQL backend.

I have small, very straightforeward VB.NET Windows Forms app that reads and writes to a remote MySQL instance. Only a few users, but a couple are in Asia, and the db resides in the Amazon Cloud.

Anyways, none of the writes are db intensive - in almost every case I'm hitting well organized indexes, mostly PKs. Still, I'm new to this type of architecture (and perhaps it's not perfect, it maybe screams out for a WEB-based app, but I'm not an ASP guy...). I'm mostly concerned about maintaining absolute transactional integrity. I would like some advice - code examples - regarding the best way to programmatically manage the sorts of inserts and updates and selects I'm performing. Any pointers to best practices in these various regards would be greatly appreciated.

Mostly, I'd like error handling code that helps to confirm connection status and manages rollbacks & commits.

*No points awarded if answers don't have code, links to code*

Insert\Update example:

Dim conn As New MySqlConnection(strMySQLConnectString)
                   
    Dim cmd As New MySqlCommand
    Dim params As MySqlParameterCollection = cmd.Parameters
    cmd.Connection = conn
    cmd.CommandType = CommandType.Text
    conn.Open()

    'updating user values with default values
    cmd.CommandText = "update users set name = 'Player' where id = " & strUserId & ""
    cmd.ExecuteNonQuery()
    'here we enter into the transaction_history table

    cmd.CommandText = "insert into transaction_history (user_id) values (" & CInt(Me.txtUserID.Text) & ");"
    cmd.ExecuteNonQuery()
    conn.Close()

Select example:

Dim strConnect As String = strMySQLConnectString
Dim FileSQL As String

FileSQL = "select users.* from users where id = " & CInt(Me.txtUserID.Text) & ";"

Dim conReader As New MySqlConnection(strConnect)
Dim conString As New MySqlCommand(FileSQL, conReader)
conReader.Open()

Dim drReader As MySqlDataReader
drReader = conString.ExecuteReader(CommandBehavior.CloseConnection)

Do While drReader.Read()
   
strUserId = drReader.Item("id").ToString
strUserName = drReader.Item("name").ToString
strUserEmail = drReader.Item("email").ToString
strUserCreateDate = drReader.Item("created").ToString
strUserExperience = drReader.Item("exp").ToString
strUserLevel = drReader.Item("level").ToString
strUserLosses = drReader.Item("losses").ToString
strUserRating = drReader.Item("rating").ToString
strUserRatingMu = drReader.Item("rating_mu").ToString
strUserRatingSigma = drReader.Item("rating_sigma").ToString
strUserGold = drReader.Item("gold").ToString
strUserCrystals = drReader.Item("crystals").ToString
strUserReferer = drReader.Item("referer").ToString
   
Loop

conReader.Close()
drReader.Close()

-----------------

TIA!

c.
0
Comment
Question by:crafuse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:crafuse
ID: 36581991
bump

;-P
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582171
You comment above had an opposite effect!!! EE sends out email notifications automatically if no comment is posted to a question after a given number of hours but you cancelled that.

Now to the point. Where are transactions? I dont see any. Is your concern referential integrity of data or concurrency violations?
0
 

Author Comment

by:crafuse
ID: 36582286

mostly concurrency issues, thought i was clear. you don't agree writes are transactions? anyways, i guess i'm mostly concerned that connections to the db are opened and closed successfully, and if there's any interruption within, that i can somehow flag this. i only write to a few key tables now and then, but it's important that data and transactional 'integrity' is maintained. i can't really afford any screw-ups...ideas?

(and no more bumps...)

c.

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 36582305
I thought you are talking about explicit transactions. As I said, if you have not gone much far in the development, consider doing this as a web. It will be very slow as a winforms app.
0
 

Author Comment

by:crafuse
ID: 36582360
it is already done, as a winforms app. should it be ported? would it be that much faster? why?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 36582393
>would it be that much faster? why?
Because it would not be transporting a lot of data over network.
0
 

Author Closing Comment

by:crafuse
ID: 36711785
feeble.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question