|
You last visited: Today at 07:44
Advertisement
.net MySQL/ MariaDB Class
Discussion on .net MySQL/ MariaDB Class within the Coding Snippets forum part of the Coding Releases category.
08/30/2017, 12:48
|
#1
|
elite*gold: 0
Join Date: Apr 2016
Posts: 1,452
Received Thanks: 202
|
.net MySQL/ MariaDB Class
VB.NET:
Code:
Imports MySql
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class MySQL
' Class to connect and start mysql queries
'###########################################
' Attributes
Private dbConnection As MySqlConnection
Private serverFeedback As DataTable = Nothing
Private connectionString As String = "server=;uid=;pwd=;database=;"
Public query As String
Public parameters As New List(Of String)
''' <summary>
''' Creates a mysql instance and connection through official mysql lib
''' </summary>
Sub New()
dbConnection = New MySqlConnection
dbConnection.ConnectionString = connectionString
Try
dbConnection.Open()
Catch ex As Exception
MessageBox.Show("Error", "MySQL Connection failed!" + vbNewLine + ex.Message, MessageBoxButtons.OK, icon:=MessageBoxIcon.Error)
End Try
End Sub
''' <summary>
''' Executes query and saves the feedback in *serverFeedback*
''' </summary>
Public Function executeQuery() As Boolean
Dim cmd As New MySqlCommand(query, dbConnection)
'Parameter binding
Dim i As Integer = 0
For Each parameter As String In Me.parameters
cmd.Parameters.AddWithValue(i.ToString(), parameter)
i += 1
Next
'Execute Query
Try
'Get and write response
Dim da As New MySqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, 0)
If ds.Tables.Count > 0 Then
Dim dt As DataTable = ds.Tables(0)
serverFeedback = dt
Else
serverFeedback = Nothing
End If
Return True
Catch ex As Exception
MessageBox.Show(String.Format("MySQL Query Execute failed!{0}{1}", vbNewLine, ex.Message), "Error", MessageBoxButtons.OK, icon:=MessageBoxIcon.Error)
Return False
End Try
End Function
''' <summary>
''' Attribute return function
''' </summary>
''' <returns>Server feedback as a DataTable</returns>
Public Function getServerReturn()
Return serverFeedback
End Function
''' <summary>
''' Closes MySQL Connection. Object not usable after calling this!
''' </summary>
Public Sub closeConnection()
dbConnection.Close()
Me.Finalize()
End Sub
End Class
C#:
Code:
using MySql.Data.MySqlClient;
public class MySQL {
// Class to connect and start mysql queries
// ###########################################
// Attributes
private MySqlConnection dbConnection;
private DataTable serverFeedback = null;
private const string connectionString = "server=;uid=;pwd=;database=;";
public string query;
public List<string> parameters = new List<string>();
MySQL() {
dbConnection = new MySqlConnection();
dbConnection.ConnectionString = connectionString;
try {
dbConnection.Open();
}
catch (Exception ex) {
MessageBox.Show("Error", ("MySQL Connection failed!" + ("\r\n" + ex.Message)), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// '' <summary>
// '' Executes query and saves the feedback in *serverFeedback*
// '' </summary>
public bool executeQuery() {
MySqlCommand cmd = new MySqlCommand(query, dbConnection);
// Parameter binding
int i = 0;
foreach (string parameter in this.parameters) {
cmd.Parameters.AddWithValue(i.ToString(), parameter);
i++;
}
// Execute Query
try {
// Get and write response
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, 0);
if ((ds.Tables.Count > 0)) {
DataTable dt = ds.Tables[0];
serverFeedback = dt;
}
else {
serverFeedback = null;
}
return true;
}
catch (Exception ex) {
MessageBox.Show(string.Format("MySQL Query Execute failed!{0}{1}", "\r\n", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// '' <summary>
// '' Attribute return function
// '' </summary>
// '' <returns>Server feedback as a DataTable</returns>
public void getServerReturn() {
return serverFeedback;
}
// '' <summary>
// '' Closes MySQL Connection. Object not usable after calling this!
// '' </summary>
public void closeConnection() {
dbConnection.Close();
this.Finalize();
}
}
You need this MySQL Connector:
|
|
|
08/31/2017, 19:14
|
#2
|
elite*gold: 2222
Join Date: May 2010
Posts: 6,846
Received Thanks: 5,099
|
I just have checked the C# code but I assume the VB.Net may work the same. So here is some feedback about several issues I noticed by quickly scanning your code:
1: In sense to use this class as a MySQL wrapper you should be able to pass the connection data through the constructor and building the connection string dynamically instead of defining them during compile time and using the pre defined connection string.
2: Do not catch an exception and show a message box with the error in a class you may want to spread. In general, this type of error handling belongs to the developer who wants to use your lib.
3: Same for the query as for the constructor. Pass the query as parameter so it can be used for any query.
4: Instead of the closeConnection you should implement  interface.
|
|
|
08/31/2017, 23:33
|
#3
|
elite*gold: 0
Join Date: Apr 2016
Posts: 1,452
Received Thanks: 202
|
Quote:
Originally Posted by Serraniel
I just have checked the C# code but I assume the VB.Net may work the same. So here is some feedback about several issues I noticed by quickly scanning your code:
1: In sense to use this class as a MySQL wrapper you should be able to pass the connection data through the constructor and building the connection string dynamically instead of defining them during compile time and using the pre defined connection string.
2: Do not catch an exception and show a message box with the error in a class you may want to spread. In general, this type of error handling belongs to the developer who wants to use your lib.
3: Same for the query as for the constructor. Pass the query as parameter so it can be used for any query.
4: Instead of the closeConnection you should implement  interface.
|
Ye thanks, that is actually an old version. handling exceptions and printing them is pretty bad i know, but it was for testing purporse only xd. thanks for feedback!
|
|
|
09/10/2017, 07:58
|
#4
|
elite*gold: 0
Join Date: May 2013
Posts: 175
Received Thanks: 122
|
This is fairly pointless/useless, to be honest. Your class does not offer any real useful features or expand off the already available features of the MySQL connector itself. There are several errors with your code as well, such as returning a value in a void function.
|
|
|
 |
Similar Threads
|
Mysql funktioniert nicht.. service mysql status mysql does not exist in /etc/rc.d
07/09/2015 - Metin2 Private Server - 8 Replies
Hey,
mein Mysql Server funktíoniert von jetzt auf gleich nicht mehr..
Kam aus dem Freibad und alles war down..
Wenn ich den Mysql Server starten will sagt er mir:
" service mysql status
mysql does not exist in /etc/rc.d or the local startup
directories (/usr/local/etc/rc.d) "
Und wenn ich meinen Metin Server starte "cant connect to 127.0.0.1" weil der Mysql Server down ist..
|
[How To] Install CentOS 7 Server MariaDB
12/29/2014 - Last Chaos Private Server - 4 Replies
Viel Spaß.
https://www.youtube.com/watch?v=x2gQ8xDfeNs&f eature=youtu.be
1. yum update
2. yum install -y mysql mysql-server mysql-devel mysql-libs php-mysql httpd php gcc-c++ libstdc++.so.6 libz.so.1 libstdc++-libc6.2-2.so.3 libgssapi_krb5.so.2 screen lm_sensors lm_sensors-devel gtk+ php-devel
3. yum install httpd
4. systemctl start httpd.service
5. systemctl enable httpd.service
|
Security vulnerability in MySQL/MariaDB sql/password.c
06/15/2012 - Metin2 PServer Guides & Strategies - 10 Replies
Something very important for all
that article is not mine i am just sharing information
"Hi
We have recently found a serious security bug in MariaDB and MySQL.
So, here, we'd like to let you know about what the issue and its impact
is. At the end you can find a patch, in case you need to patch an older
unsuported MySQL version.
|
setup Net microsoft net Framework sp 3.5 sp1 log all setup Net microsoft net Framewo
11/17/2011 - Rappelz - 0 Replies
setup Net microsoft net Framework sp 3.5 sp1 log all
setup Net microsoft net Framework sp 3.5 sp1 log all some proplem
this ):
here
........
http://www.elitepvpers.com/forum/rappelz/1542117- help-decrypt-client-3.html#post13918381
help @@ PLZ ):
|
All times are GMT +1. The time now is 07:44.
|
|