C#C
C#2y ago
Janek

✅ Microsoft sql unable to connect. What I'm missing?

Hey!
Does anybody know what I'm missing as I'm trying to connect to mysql?
I get InvalidOperationExpection on SqlConnection.Open() function call. (System.InvalidOperationException: 'Internal connection fatal error.)
Here is the ConnectionString: Data Source = "127.0.0.1, 3307"; Initial Catalog = mysql_db; User ID = root; Password = root
Ip, port, db, username and password is correct as I was able to login as root use using MySQL Workbench software.


GetBuilder function:
       internal SqlConnectionStringBuilder GetBuilder()
        {
            return new SqlConnectionStringBuilder
            {
                DataSource = Server,
                UserID = Username,
                Password = Password,
                InitialCatalog = Database
            };
        }

GetConnection function
        internal SqlConnection GetConnection(SqlConnectionStringBuilder builder = null)
        {
            SqlConnection connection = null;
            try
            {
                connection = builder == null ? new SqlConnection(GetBuilder().ConnectionString)
                                             : new SqlConnection(builder.ConnectionString);
            }
            catch (Exception err)
            {
                Console.WriteLine($"ERROR::Db_Connection::GetConnection:: {err}");
            }
            return connection;
        }


SendQuery function calls GetConnection after connection.Open is called which gives me the error.
                SqlConnection connection = GetConnection();
                connection.Open();
Was this page helpful?