test stuff
This commit is contained in:
14
test/dotnet/DatabaseTest.csproj
Normal file
14
test/dotnet/DatabaseTest.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<ApplicationIcon />
|
||||
<StartupObject>DatabaseTest.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySqlConnector" Version="0.56" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
46
test/dotnet/Program.cs
Normal file
46
test/dotnet/Program.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace DatabaseTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private const string SERVER_ADDRESS = "127.0.0.1";
|
||||
private const string SERVER_PORT = "3306";
|
||||
private const string DATABASE_NAME = "testdb";
|
||||
private const string USERNAME = "testuser";
|
||||
private const string PASSWORD = "test123";
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string connectionStr = $"Server={SERVER_ADDRESS};Port={SERVER_PORT};Database={DATABASE_NAME};Uid={USERNAME};Pwd={PASSWORD}";
|
||||
|
||||
MySqlConnection con = new MySqlConnection();
|
||||
con.ConnectionString = connectionStr;
|
||||
|
||||
try
|
||||
{
|
||||
con.Open();
|
||||
|
||||
MySqlCommand cmd = con.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM testtable";
|
||||
var reader = cmd.ExecuteReader();
|
||||
DataTable dt = new DataTable();
|
||||
dt.Load(reader);
|
||||
|
||||
con.Close();
|
||||
}
|
||||
catch (MySqlException sqlEx)
|
||||
{
|
||||
Console.WriteLine(sqlEx.Message);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(sqlEx.InnerException?.Message);
|
||||
}
|
||||
|
||||
Console.WriteLine("Press any key to close.");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user