none
C# connect to my web sql RRS feed

  • Question

  • Hello,

    Is it possible connect application C# languages with web site mysql. I tryed use this line, but application not connected to mysql

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                string connetionString = null;
                MySqlConnection cnn;

    connetionString = "server=vilkdalgis.serveriai.lt; database=duomynys;uid=login;pwd=******";

    cnn = new MySqlConnection(connetionString);
                try
                {
                    cnn.Open();
                    MessageBox.Show("Connection Open ! ");
                    cnn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Can not open connection ! ");
                }
    }

    Saturday, November 9, 2019 12:12 PM

All replies

  • Please explain exactly what happened and the error message from the catch variable ex.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Saturday, November 9, 2019 12:26 PM
    Moderator
  • My question is simple

    Could I use string "connetionString = "server=vilkdalgis.serveriai.lt;database=orexlt_duomynys;uid=orexlt;pwd=******;";" when my mysql server is not localhost, but server address is vilkdalgis.serveriai.lt

    Now got  MessageBox.Show("Can not open connection ! ");




    Saturday, November 9, 2019 3:50 PM
  • If you are using ASP.Net then you should be asking in the ASP.Net forums. You say "web site" so the question is very confusing. We are not sure what you are asking. Hopefully you understand what you are asking but we do not.

    Your code implies your program is a Windows Forms program. If so then your question would be less confusing if it were in the Windows Forms forum.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, November 9, 2019 5:42 PM
  • My question is simple

    Actually it is not, not for those of us trying to help.



    Sam Hobbs
    SimpleSamples.Info

    Saturday, November 9, 2019 5:43 PM
  • My question is simple

    Could I use string "connetionString = "server=vilkdalgis.serveriai.lt;database=orexlt_duomynys;uid=orexlt;pwd=******;";" when my mysql server is not localhost, but server address is vilkdalgis.serveriai.lt

    Now got  MessageBox.Show("Can not open connection ! ");




    No,  you normally don't connect directly to a database hosted in the manner your are talking about. You would use a Web program like an ASP.NET Web service or an ASP.NET WebAPI.
    Saturday, November 9, 2019 10:21 PM
  • No, you normally don't connect directly to a database hosted in the manner your are talking about. You would use a Web program like an ASP.NET Web service or an ASP.NET WebAPI.

    But isn't that what a cloud database is? A database hosted in another site, somewhere in the internet world, that can be used from anywhere in the internet world? I agree that normally it is not a database dedicated to a website. I do not know if all databases dedicated to a website could be used like that but I assume some can. Certainly a cloud database (such as in Azure) could be used in both ways.

    We have not gotten clarification from sarunasz. In my experience when the person requesting assistance does not clarify the problem and others speculate about what they need then the discussion grows so much that it can become useless. So I hope sarunasz does clarify the requirements.



    Sam Hobbs
    SimpleSamples.Info


    Sunday, November 10, 2019 12:16 AM
  • But isn't that what a cloud database is? A database hosted in another site, somewhere in the internet world, that can be used from anywhere in the internet world?

    I worked a project once where the solution eventually connected to a database hosting provider to store the data. I wouldn't call it a cloud database. 

    Sunday, November 10, 2019 1:14 PM