DAO dsnless connection to mysql database opens as readonly

Hi,
I'm trying to add a record with vba to a remote mysql database table using a dsnless dao connection.

Unfortunately I keep getting the "Cannot Update. Database or object is read-only".

I am able to add records using a DSN connection so I think the problem is somewhere in the code I'm using.

Any ideas?
Public Sub testDsnless()
    Dim dbMySQL As Database
    Dim cnMySQL As DAO.Connection
    Dim rsMySQL As DAO.Recordset
    Dim sDSN As String, qrMySQL As String
    
    sDSN = "ODBC;DRIVER={MySQL ODBC 3.51 Driver};" _ 
& " SERVER=www.myserver.com;DATABASE=mydatabase;" _
& " UID=myusername;PWD=mypassword;"
    Set dbMySQL = OpenDatabase("", False, False, sDSN)
    
    qrMySQL = "SELECT * FROM tableName;"
    Set rsMySQL = dbMySQL.OpenRecordset(qrMySQL)
    
    rsMySQL.AddNew
    rsMySQL!ID = 1000
    rsMySQL.Update
End Sub

Open in new window

aragorn_grAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TextReportCommented:
Pass through queries are read only, you need to either attache the table to use the AddNew or do an INSERT in the passthrough query.
Cheers, Andrew
0
TextReportCommented:
Sorry mis read your question, your not using passthrough's.

Can you confirm if you set sDSN to use the DSN this then works for you.

Cheers, Andrew
0
aragorn_grAuthor Commented:
> Can you confirm if you set sDSN to use the DSN this then works for you.

If I understand correctly, you want me to change line 10 as follows (remove the False at options parameter)

Set dbMySQL = OpenDatabase("", , False, sDSN)

and get the SELECT Data Source message window when i run the code. I get the same error again...

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

TextReportCommented:
I am refering to the ODBC connect string, the one you are using is a DSN Less connection as you are specifying the driver to use. A DSN Connection has DSN= in the connect string. Pleas try this instead of the DSN Less option you are using.
Cheers, Andrew
0
aragorn_grAuthor Commented:
OK, I've modified sDSN to be:
sDSN = "ODBC;DSN=dsn_name;DRIVER={MySQL ODBC 3.51 Driver};"
and still the same error. The connection is made successfully but I have read only access.
0
TextReportCommented:
OK and if you do a File Attach is it read-write?
Cheers, Andrew
0
aragorn_grAuthor Commented:
I dont know what a File Attach is or how am I supposed to do one...

I can tell you that if I link to the mysql database tables in an mdb using the same dsn, I have read write access.
0
TextReportCommented:
Probably talking about the same thing, File Menu, Get External Data, Link Tables.
This would imply that the attached tables is correctly identifying the Primary Key whereas the OpenDatabase is not.
Not sure what we can do now excepty use the linked table.
Cheers, Andrew
0
TextReportCommented:
OK tested with MS SQL Server and worked Ok with a slight modification

    Set rsMySQL = dbMySQL.OpenRecordset(qrMySQL, dbOpenDynaset, dbSeeChanges)

Cheers, Andrew
0
aragorn_grAuthor Commented:
Unfortunately it does not work with mysql :-(
0
TextReportCommented:
Do you have a primary key or unique key on the table?
Cheers, Andrew
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aragorn_grAuthor Commented:
No. I thought i did because the table was exported but seems like it didn't retain the Primary Key... I've set it and everything is fine! I'm accepting your answer with id 20824180 as a solution

Thanks a lot Andrew!
0
TextReportCommented:
No problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.