Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

[Need help] cannot get a connection to my MySql database

$
0
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            gumb();
            Label2.Text = (TextBox1.Text+" "+"Thank you for participating");
        }
        protected void gumb()
        {
            SqlConnection myConnection = new SqlConnection("user id= ; password= ; server= ; database=; ");           
            do
            {
                try
                {
                    myConnection.Open();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            while (myConnection.State != System.Data.ConnectionState.Open);
            SqlCommand myCommand = new SqlCommand("INSERT INTO emails (ime, priimek, email) " + "Values ('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"')", myConnection);
            myCommand.ExecuteNonQuery();
            try
            {
                myConnection.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }


        }    
    }
}

i made this program so that it stores emails of the users that want to participate in a contest but i cant connect to my MySql host

i get this error in the open catch exeption loop: A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Data.dll


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>