Tested for connection to MariaDB
This commit is contained in:
parent
ace8f88ec1
commit
38a7195040
@ -7,6 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
|
<PackageReference Include="MySql.Data" Version="8.0.27" />
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Archive", "..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj", "{B88ED0D9-72E2-4245-BD8F-856FF42E500C}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -35,6 +39,14 @@ Global
|
|||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B88ED0D9-72E2-4245-BD8F-856FF42E500C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -1,28 +1,145 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
using System.Data.SqlClient;
|
//using System.Data.SqlClient;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
|
//using MySql.Data.MySqlClient;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
|
||||||
public class HobbyMain
|
public class HobbyMain
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello World!");
|
// Testing file compression Start
|
||||||
|
//Console.WriteLine("Hello World!");
|
||||||
|
|
||||||
// Testing Compressing a file
|
//// Testing Compressing a file
|
||||||
string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando";
|
//string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando";
|
||||||
//string fileName = @"arhiving2.txt";
|
////string fileName = @"arhiving2.txt";
|
||||||
FileInfo fileInfo = new FileInfo(fileName);
|
//FileInfo fileInfo = new FileInfo(fileName);
|
||||||
|
|
||||||
Console.WriteLine("File Name: {0}", fileInfo.FullName);
|
//Console.WriteLine("File Name: {0}", fileInfo.FullName);
|
||||||
|
|
||||||
SQLSource sqlSource = new SQLSource();
|
//SQLSource sqlSource = new SQLSource();
|
||||||
bool res = sqlSource.CompressFile(fileName);
|
//bool res = sqlSource.CompressFile(fileName);
|
||||||
//bool res = CompressFile(fileName);
|
////bool res = CompressFile(fileName);
|
||||||
Console.WriteLine(res);
|
//Console.WriteLine(res);
|
||||||
|
|
||||||
Console.WriteLine(CreateFileName());
|
//Console.WriteLine(CreateFileName());
|
||||||
|
|
||||||
|
// Testing File compression end
|
||||||
|
|
||||||
|
// testing end
|
||||||
|
|
||||||
|
// Testing connection to MariaDB
|
||||||
|
|
||||||
|
string connString = "user id=root;" + "password=Teamhobby;server=localhost;" + "Trusted_Connection=yes;" + "database=Alatreon; " + "connection timeout=5";
|
||||||
|
string connMariaDB = "server=localhost;port=3306;uid=root;pwd=Teamhobby;connection timeout=5";
|
||||||
|
var conn = new SqlConnection(connString);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// SqlConnection conn = new SqlConnection(connString);
|
||||||
|
string sqlQ = "Select * from log;";
|
||||||
|
|
||||||
|
//MySql.Data.MySqlClient.MySqlConnection connect;
|
||||||
|
|
||||||
|
//try
|
||||||
|
//{
|
||||||
|
// Console.WriteLine("Open connection: ");
|
||||||
|
// //connect = new MySql.Data.MySqlClient.MySqlConnection();
|
||||||
|
// //connect.ConnectionString = connMariaDB;
|
||||||
|
// //connect.Open();
|
||||||
|
// conn.Open();
|
||||||
|
|
||||||
|
// SqlCommand cmd = new SqlCommand(sqlQ, conn);
|
||||||
|
|
||||||
|
// SqlDataReader myReader = cmd.ExecuteReader();
|
||||||
|
// while (myReader.Read())
|
||||||
|
// {
|
||||||
|
// Console.WriteLine(myReader["Column1"].ToString());
|
||||||
|
// Console.WriteLine(myReader["Column2"].ToString());
|
||||||
|
// }
|
||||||
|
// conn.Close();
|
||||||
|
|
||||||
|
// //if (connect.State == System.Data.ConnectionState.Open)
|
||||||
|
// //{
|
||||||
|
// // Console.WriteLine("Connection established");
|
||||||
|
// //}
|
||||||
|
// //connect.Close();
|
||||||
|
|
||||||
|
//}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine("Opening connection: ");
|
||||||
|
//Connection string for Connector/ODBC 3.51
|
||||||
|
string MyConString = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
|
||||||
|
//Connect to MySQL using Connector/ODBC
|
||||||
|
//OdbcConnection MyConnection = new OdbcConnection(MyConString);
|
||||||
|
//MyConnection.Open();
|
||||||
|
|
||||||
|
//Console.WriteLine("\n !!! success, connected successfully !!!\n");
|
||||||
|
|
||||||
|
////Display connection information
|
||||||
|
//Console.WriteLine("Connection Information:");
|
||||||
|
//Console.WriteLine("\tConnection String:" +
|
||||||
|
// MyConnection.ConnectionString);
|
||||||
|
//Console.WriteLine("\tConnection Timeout:" +
|
||||||
|
// MyConnection.ConnectionTimeout);
|
||||||
|
//Console.WriteLine("\tDatabase:" +
|
||||||
|
// MyConnection.Database);
|
||||||
|
//Console.WriteLine("\tDataSource:" +
|
||||||
|
// MyConnection.DataSource);
|
||||||
|
//Console.WriteLine("\tDriver:" +
|
||||||
|
// MyConnection.Driver);
|
||||||
|
//Console.WriteLine("\tServerVersion:" +
|
||||||
|
// MyConnection.ServerVersion);
|
||||||
|
|
||||||
|
//Console.WriteLine("Connection Successful");
|
||||||
|
|
||||||
|
ReadData(MyConString);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
Console.WriteLine("COnnection failed");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ReadData(string connectionString)
|
||||||
|
{
|
||||||
|
string queryString = "SELECT logID from log;";
|
||||||
|
|
||||||
|
using (OdbcConnection connection = new OdbcConnection(connectionString))
|
||||||
|
{
|
||||||
|
OdbcCommand command = new OdbcCommand(queryString, connection);
|
||||||
|
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
// Execute the DataReader and access the data.
|
||||||
|
OdbcDataReader reader = command.ExecuteReader();
|
||||||
|
Console.WriteLine("Read the database");
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
//Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3],reader[4], reader[5]);
|
||||||
|
Console.WriteLine("Col A: {0} ", reader[0]);
|
||||||
|
//Console.WriteLine("Column: " + reader.FieldCount);
|
||||||
|
//Console.WriteLine("Column={1}", reader[1]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call Close when done reading.
|
||||||
|
reader.Close();
|
||||||
|
connection.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateFileName()
|
public static string CreateFileName()
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user