❔ My first time using mySql workbench with c#

im trying to connect mysql to my HabitTrackerand i keep getting "Unable to connect to any of the specified MySql hosts." in the console. Not 100% on what im doing
static void Main(string[] args)
{
MySql.Data.MySqlClient.MySqlConnection conn;
string connectionString = @"Data Source=HabitTracker.db";

try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = connectionString;
conn.Open();
var tableCmd = conn.CreateCommand();

tableCmd.CommandText =
@"CREATE TABLE IF NOT EXISTS drinking_water(
Id Integer PRIMARY KEY AUTOINCREMENT,
Date_Of DATE,
Quantity INTEGER
)";
tableCmd.ExecuteNonQuery();
conn.Close();
}
catch(MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
}
}
static void Main(string[] args)
{
MySql.Data.MySqlClient.MySqlConnection conn;
string connectionString = @"Data Source=HabitTracker.db";

try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = connectionString;
conn.Open();
var tableCmd = conn.CreateCommand();

tableCmd.CommandText =
@"CREATE TABLE IF NOT EXISTS drinking_water(
Id Integer PRIMARY KEY AUTOINCREMENT,
Date_Of DATE,
Quantity INTEGER
)";
tableCmd.ExecuteNonQuery();
conn.Close();
}
catch(MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
}
}
5 Replies
Angius
Angius2y ago
You're using a MySqlConnection, but the connection string tells me it's an SQLite file
strawhatgoofy
strawhatgoofyOP2y ago
oop gotcha something like this? "server=127.0.0.1;uid=root;pwd=12345;database=test"
Angius
Angius2y ago
ye
strawhatgoofy
strawhatgoofyOP2y ago
yea i had that earlier and i got an access denied for user message ill keep trying ty oh. i didnt add '.db' to the sql database lol
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server