locked
access database row and edit one line of existing user RRS feed

  • Question

  • ok what i am trying to do to the best of my ability is create a user username and password witch is done perfectly fine

    the issue i am having is once the user is registered i want to save there machine id i have the following code to do so 

                    //This is my connection string i have assigned the database file address path  
                    string connString;
                    connString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};";
                    string machineidfull = processorid + mbored;
                    //This is my update query in which i am taking input from the user through windows forms and update the record.  
                    string Query = "update elfenliedtopfan5_login set users(machineid='" + machineidfull + "');";
                    //This is  MySqlConnection here i have created the object and pass my connection string.  
                    MySqlConnection MyConn2 = new MySqlConnection(connString);
                    MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
                    MySqlDataReader MyReader2;
                    MyConn2.Open();
                    MyReader2 = MyCommand2.ExecuteReader();
                    MessageBox.Show("Data Updated");
                    while (MyReader2.Read())
                    {
                    }
                    MyConn2.Close();//Connection closed here  

    but the issue i have is it gives me the following error 

    {"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(machineid='BFEBFBFF000906E9170808xxxxxxx')' at line 1"}

    also i know its unrelated i think to this but is there a way to ban users as well so if the machine id is not listed as a accessed user then it will stop user using my program 

     
    Tuesday, July 28, 2020 5:04 PM

All replies

  • You are posting in a forum specific to SQL Server. Your error message indicates you are using MariaDB and you will be better served posting to a more appropriate forum. 

    • Proposed as answer by Naomi N Tuesday, July 28, 2020 10:03 PM
    Tuesday, July 28, 2020 5:37 PM
  • Also - your code appears to generate the following sql statement

    update elfenliedtopfan5_login set users(machineid='BFEBFBFF000906E9170808xxxxxxx');

    This is not valid tsql and i doubt it is valid sql for your db engine. Based on your description I would expect to see something like: 

    update elfenliedtopfan5_login set machineid='BFEBFBFF000906E9170808xxxxxxx'
    where <pk> = <some value> ;

    But that is just a guess - especially without any knowledge of the tables. Posting in a mariadb forum (or perhaps stack overflow) would be a far better approach. 

    • Proposed as answer by Naomi N Tuesday, July 28, 2020 10:03 PM
    Tuesday, July 28, 2020 7:51 PM
  • Quick google search brings this

    https://mariadb.com/kb/en/update/

    However, we need to see how to correctly pass parameters to MariaDB as your code is not very safe. You may want to research on that first.

    Also, you may ask your question in C# forum here as I see several problems with the posted code.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles


    • Edited by Naomi N Tuesday, July 28, 2020 10:10 PM
    Tuesday, July 28, 2020 10:07 PM
  • Hi elfenliedtopfan55,

    I tried to find MariaDB forum for you, but I couldn't find it.

    You can try to  find relevant knowledge on MariaDB official website.

    In addition, you can check whether you have set relevant permissions when you create a new user.

    Please refer to https://mariadb.com/kb/en/create-user/.

    Best Regards
    Echo


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com





    • Edited by Echo Liuz Wednesday, July 29, 2020 7:41 AM
    Wednesday, July 29, 2020 7:35 AM
  • Hi elfenliedtopfan55,

    Has your problem been solved? If it is solved, please mark the point that you 
    think is correct as an answer. This can help others who encounter similar problems.

    Best Regards
    Echo


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, July 30, 2020 5:29 AM