First question: is it possible to programmatically create both a MySQL instance and a database within it?
I'm working in VB.NET; have MySQL Connector Net v6.9.8 installed. I'd like to write a program that can create/use a MySQL database without MySQL having to be installed on the user's PC - but haven't yet managed to succeed at it.
I've found, and tried, several snippets but it looks like they all are predicated on a running instance of MySQL being in place. The only mentions I've been able to find of creating an instance of MySQL dealt with installing the product.
The code from my latest attempt:
I'm working in VB.NET; have MySQL Connector Net v6.9.8 installed. I'd like to write a program that can create/use a MySQL database without MySQL having to be installed on the user's PC - but haven't yet managed to succeed at it.
I've found, and tried, several snippets but it looks like they all are predicated on a running instance of MySQL being in place. The only mentions I've been able to find of creating an instance of MySQL dealt with installing the product.
The code from my latest attempt:
Code:
Imports MySql.Data.MySqlClient
Public Class frmMain
Dim cnData As MySqlConnection
Dim cnStr As String
Dim cmData As MySqlCommand
Dim cmdSQL As String
Private Sub frmMain_Load(sender As Object, e As System.EventArgs) Handles Me.Load
cnStr = "Server=localhost; userid=root; password=mysql;"
Try
cnData = New MySqlConnection(cnStr)
cnData.Open()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Try
cmData = New MySqlCommand("create database if not exists SBE49", cnData)
cmData.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Try
cnData.ChangeDatabase("SBE49")
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Try
cmdSQL = "create table if not exists Report (" & _
"rYear int,rMonth int,Precinct char(4)," & _
"Office varchar(50),Candidate varchar(50)," & _
"Votes int,CD int,SEQ int)"
cmData = New MySqlCommand(cmdSQL, cnData)
cmData.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
cnData.Close()
End
End Sub
End Class