I thought I would share a fix with everyone that took a while for me to track down.
When inserting string data > 255 characters (for example when storing the output from RADEDIT.html) into a Microsoft Access database memo field you will sometimes get the error below
ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value
Exception Details: System.Data.Odbc.OdbcException: ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value
I say sometimes as I have some pages using the code below which work fine and others that failed every single time.
Code that produces the error
Dim dbconn As New Odbc.OdbcConnection
dbconn.ConnectionString = Global.bmfdb
dbconn.Open()
Dim sqlcmd As New Odbc.OdbcCommand
Dim da As New Odbc.OdbcDataAdapter
sqlcmd.Connection = dbconn
sqlcmd.CommandText = "update tablex set thememofield=? where pageid=?"
sqlcmd.Parameters.Add("@thememofield", RADEDITpagetext.Html)
sqlcmd.Parameters.Add("@pageid", viewstate("pageid"))
sqlcmd.ExecuteNonQuery()
sqlcmd.Dispose()
dbconn.Dispose()
Fixed CodeDim dbconn As New Odbc.OdbcConnection
dbconn.ConnectionString = Global.bmfdb
dbconn.Open()
Dim sqlcmd As New Odbc.OdbcCommand
Dim da As New Odbc.OdbcDataAdapter
sqlcmd.Connection = dbconn
sqlcmd.CommandText = "update tablex set thememofield=? where pageid=?"
Dim thememofield As Odbc.OdbcParameter = sqlcmd.CreateParameter
thememofield.OdbcType = Odbc.OdbcType.Text
thememofield.ParameterName = "@thememofield"
thememofield.Value = RADEDITpagetext.Html
sqlcmd.Parameters.Add(thememofield)
sqlcmd.Parameters.Add("@pageid", viewstate("pageid"))
sqlcmd.ExecuteNonQuery()
sqlcmd.Dispose()
dbconn.Dispose()
Based on the code that works it seems that the ODBC driver is misidentifying the data that is about to be inserted into the memo field. By explicitly telling it whats what everything works. Maybe I should be less lazy with my code!
I should point out that not using parameters does not fix the problem either. Using a paramater as specified in the working code seems to be the only way around it this.
This doesn't work:
sqlcmd.CommandText = "update tablex set thememofield='" & replacequotesfunction(RADEDITpagetext.Html) & "' where pageid=?"I have not come across this problem in MySQL (the only other database I use). This fix came about from an article on an identical problem in classic ASP at Experts Exchange.
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21886137.html