Click here to Skip to main content
14,976,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i'm using visual studios and phpmyadmin shared server to host a database, when i try to send data to the database i get the insert command denied to user message.
VBScript
<pre>MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString =
        "server=213.171.200.99;Database=database name;uid=user name;pwd=password"
        Dim READER As MySqlDataReader

        Try
            MysqlConn.Open()
            Dim Query As String
            Query = "insert into database.ToughEasy (Product, Location, Ammount) values ('" & TextBox_Product.Text & "','" & TextBox_Location.Text & "')"
            COMMAND = New MySqlCommand(Query, MysqlConn)
            READER = COMMAND.ExecuteReader

            MessageBox.Show("Data saved")

            MysqlConn.Close()


        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            MysqlConn.Dispose()

        End Try


What I have tried:

ive tried most google answers i can find but as its a shared server i can't change the permissions and the hosting company cant help.
Posted
Updated 8-Mar-21 0:40am
Comments
Richard MacCutchan 8-Mar-21 6:41am
   
You forgot the Amount value in your command string. Also, INSERT does not return a reader object, you should use ExecuteNonQuery.

And finally, using string concatenation to build SQL commands is exceedingly dangerous, as explained by Patrice below.

VB
MysqlConn.ConnectionString =
"server=213.171.200.99;Database=database name;uid=user name;pwd=password"

Are you sure 'user' is a real user all 'password' its real password ?

VB
Query = "insert into database.ToughEasy (Product, Location, Ammount) values ('" & TextBox_Product.Text & "','" & TextBox_Location.Text & "')"

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
   
MySql users have rights associated with them, so that they can only perform tasks that they are allowed to do - this is to cut down on damage from both badly coded queries, and Sql Injection attacks. And normally a user is selected so that his role exactly matches what you app is allowing him to do.

Your user would not appear to have permission to INSERT into a db - you would need to either add permissions to your user role, or use a different user than does.

But don't do your queries like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900