MySQL Forums
Forum List  »  MySQL for Visual Studio

Implementing MYSQL along side MSSQL
Posted by: David DIlley
Date: February 11, 2017 01:19PM

I would like be able to expand a project I am working with to allow use of a MYSQL server as well as the MSSQL server the code now implements. I am trying to figure out a my to set the SQL server variable types at run time depending on the serve being used so I do not have to rewrite or add a whole lot of code. Below is an example (not functional) just to show what I am trying to accomplish. The code does not work of course because the compiler does not recognize the SQL variables that are assigned within a conditional statement.

Sub GetData()
If DatabaseType = MSSQL Then
Dim sqlConnectionStr As New System.Data.SqlClient.SqlConnection
Dim cmd As New System.Data.SqlClient.SqlCommand
Dim dreader As System.Data.SqlClient.SqlDataReader
ElseIf DatabaseType = MySql Then
Dim sqlConnectionStr As New MySql.Data.MySqlClient.MySqlConnection
Dim cmd As New MySql.Data.MySqlClient.MySqlCommand
Dim dreader As MySql.Data.MySqlClient.MySqlDataReader
End If
cmd.CommandType = System.Data.CommandType.Text
cmd.Parameters.Add("@ApplicationID", SqlDbType.NVarChar)
cmd.Parameters("@ApplicationID").Value = CurrentApplicationID
cmd.CommandText = "SELECT * FROM aspnetTables_Volenteers WHERE ApplicationID = @ApplicationID"
If DatabaseType = MSSQL Then
sqlConnectionStr.ConnectionString = ConfigurationManager.ConnectionStrings("MSSQL").ConnectionString
ElseIf DatabaseType = MySql Then
sqlConnectionStr.ConnectionString = ConfigurationManager.ConnectionStrings("MYSQL").ConnectionString
End If
cmd.Connection = sqlConnectionStr
dreader = cmd.ExecuteReader()
If dreader.Read() Then
Name = dreader("Name")
Address = dreader("Address")
HomePhone = dreader("HomePhone")
Cell = dreader("Cell")
End If
Catch ex As Exception
End Try
End Sub

I am thinking this is one of those cases where "There's no way to get there from here", and I am going to end up spending months rewriting code. I am hoping I can find a more efficient way. If you can't assign a type within a conditional statement, is there a way assign a "base" type and then reassign the variable to a different type at run time?

Thanks for any help you can give!

Options: ReplyQuote

Written By
Implementing MYSQL along side MSSQL
February 11, 2017 01:19PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.