locked
Problem with connecting to MySql RRS feed

  • Question

  • User-234026806 posted

    Hi There;

    I am learning how to establish a connection to mysql in c#. Here are my codes :

    protected void connect(Object Sender, CommandEventArgs arguman)
        {
            try
            {
    
                MySqlConnection connection; // bağlantı nesmenizi tanımladık
    
                string connString;
    
                MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(); //" MySqlConnectionStringBuilder" bize bağlantı kurmamızı kolaylaştıran yapı
    
                builder.UserID = "root";
    
                builder.Password = "123456";
    
                builder.Database = "connectcsharptomysql";
    
                builder.Server = "localhost";
    
                connString = builder.ToString();
    
                connection = new MySqlConnection(connString);
    
                connection.Open();
    
                Response.Write("Connection is successfull.");
    
                connection.Close();
    
            }
    
            catch (Exception ex)
            {
    
                Response.Write("Can not connected.");
                Response.Write(ex.Message);
    
    
            }

    When I run this code : I catched this error: "Keyword not supported. Parameter name: MySql.Data.MySqlClient.MySqlConnectionStringBuilder"
     any ideas?

    Wednesday, June 6, 2012 9:46 AM

All replies

  • User197322208 posted
     connString = builder.ConnectionString();

    http://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.MySqlConnectionStringBuilder.html
    Wednesday, June 6, 2012 10:13 AM
  • User-234026806 posted

    I've changed the relevant line as such: "connString = builder.ConnectionString()" but this time I've got the error: 

    Compilation Error
    
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS1955: Non-invocable member 'MySql.Data.MySqlClient.DbConnectionStringBuilder.ConnectionString' cannot be used like a method.
    


    http://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.MySqlConnectionStringBuilder.html , in this source, I 've copy/paste the code exactly as written, but at that time, I've got this error: 

    Compilation Error
    
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 
    
    Compiler Error Message: CS1061: 'MySql.Data.MySqlClient.MySqlConnectionStringBuilder' does not contain a definition for 'Host' and no extension method 'Host' accepting a first argument of type 'MySql.Data.MySqlClient.MySqlConnectionStringBuilder' could be found (are you missing a using directive or an assembly reference?)
    

    I ferret in web to connect a MySQL database in C#.I am a Java programmer and it is hard to imagine why such a  sample and simple codes do not work in order to perform a basic MySQL connection.  and I appreciate my instructor not to choose .NET and C#.  

    Wednesday, June 6, 2012 11:59 AM
  • User197322208 posted

    I've changed the relevant line as such: "connString = builder.ConnectionString()" 

    I 've copy/paste the code exactly as written,

    Sorry , you do not copy/paste exactly

    At

    http://www.devart.com/dotconnect/mysql/docs/Devart.Data.MySql~Devart.Data.MySql.MySqlConnectionStringBuilder.html , it is:

    myCSB.ConnectionString

    It is not a function, it is a property! Remove () :

    connString = builder.ConnectionString;


    Wednesday, June 6, 2012 6:06 PM
  • User-234026806 posted

    I've made the changes as you pointed out, but nothing has changed.

    I've changed my database to POSTGRESQL and the code that I found was worked. 

    http://www.codeproject.com/Articles/30989/Using-PostgreSQL-in-your-C-NET-application-An-intr

    Tuesday, June 12, 2012 10:04 AM