Saturday, July 12, 2008

Hey all!
It's my first POST here and hope to do it right.
During my last project i found some difficulty in converting an asp.net project from MS Sql database to Mysql.

Here are list of some differences that i wanted to share with you all:-

a) ->In MS Sql
add key="DBConnectionString" value="workstation id=workstationID;packet size=4096;user id=userID;data source=SourceAddress;persist security info=True;initial catalog=name;password=pwd"

->In Mysql
add key="DBConnectionString" value="Driver={MySQL ODBC 3.51 Driver}; Server=localhost;Database=databasename;uid=userID;pwd=mypassword;option=3"

b) ->In MS Sql

Imports System.Data.SqlClient

->In Mysql
Imports System.Data.Odbc

c) ->In MS Sql

Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
->In Mysql

Dim myConnection As OdbcConnection
Dim myCommand As OdbcCommand

If you are using StoredProcedures then here are the list of diffrences between MS sql and Mysql:-

d) ->In MS Sql

Dim DsLogin As New DataSet

OpenDBConnection()

Dim myDataAdapter As New SqlDataAdapter("spGetLoginInformation", OranjConnString)
myDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
Dim ParmUserName As New SqlParameter("@UserName", SqlDbType.VarChar, 15)
ParmUserName.Value = xUserName
myDataAdapter.SelectCommand.Parameters.Add(ParmUserName)
Dim ParmPwd As New SqlParameter("@Pwd", SqlDbType.VarChar, 15)
ParmPwd.Value = xPassword
myDataAdapter.SelectCommand.Parameters.Add(ParmPwd)
myDataAdapter.Fill(DsLogin, "LoginInfo")
CloseDBConnection()
->In Mysql
Dim DsLogin As New DataSet
OpenDBConnection()
Dim myDataAdapter As New OdbcDataAdapter("call spGetLoginInformation(?,?)", OranjConnString)
myDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
Dim ParmUserName As New OdbcParameter("?at_UserName", OdbcType.VarChar, 15) ParmUserName.Value = xUserName
myDataAdapter.SelectCommand.Parameters.Add(ParmUserName)
Dim ParmPwd As New OdbcParameter("?at_Pwd ", OdbcType.NVarChar, 15)

ParmPwd.Value = xPassword
myDataAdapter.SelectCommand.Parameters.Add(ParmPwd)
myDataAdapter.Fill(DsLogin, "LoginInfo")

CloseDBConnection()


Note:
(Mysql)
:-call spGetLoginInformation(?,?)- No. of question marks equal to number of variables.
e)
->In MS Sql
fieldname = "ISNULL( Max(iuserID ) ,0) + 1 "
->In Mysql

fieldname = "IFNULL(Max(iuserID ),0)+1"
Find more in next...

2 comments:

Subhasis Space said...

haaa kool codes man
these helped me a lot
i was alwayas trying for this but couldnt

thanks

Ram said...

thnks bro..