I have a database that stores teams. Each of these team names is unique. In the event that one is named Bob's Team. I have successfully managed to % encode the symbols when it is sent through the querystring to the next file. In this file I am getting an error with the SQL due to the apostrophe and I don't know how to fix it. Not quite sure about all this escaping stuff I'm reading. It's pretty confusing. Here is the line causing the problem:
strSQL = "SELECT * FROM Teams WHERE TeamName='" & TheTeamName & "'"
In the event that Bob's Team is the name of the team. The error I get is:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'TeamName='Bob's Team''.
/DeleteTeam.asp, line 35
I'd like to know what I have to do in order to make it properly delete a team with an apostrophe (and possibly other annoying symbols) in it.
To make your query work as is you can try the following:
Replace in TheTeamName the Single Quote ' by ''
Then use it in your query. (#least this works in MySQL not sure abt your DB engine but give it a try).
Note that it is better to use prepared statement to prevent SQL-Injection
Related
I'm using Simba ODBC to create a connection with Google Big Query and using SSIS (Visual Studio 2019) to read and write information on Big Query. The connection works fine and when I use the ODBC Source with the query option, I'm able to get data from Big Query and used it inside SSIS. But when I use the list of tables, I get an error as below:
Exception of HRESULT: 0xC0014020
Error in Data Flow Task[ODBC Source [100]]: SQLSTATE: 42000, Message: [Simba][BigQuery] (70) Invalid query: Invalid dataset ID ""TEST"". Dataset IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long.
I believe that this happens because the list of tables appear between ("), instead of (`).
Print of table list
The same happens when I use the ODBC Destination. Is there a way to change the format in which the table list appears ?
Obs.: On the Visual Studio 2015 this table list comes with (`) and I can connect with big query just fine.
I can see that the tool is sending "TEST" as the dataset, however, depending on if Visual Studio is using StandardSQL or LegacySQL, the dataset should be specified as:
# LegacySQL
FROM [myproject:TEST.TABLE_TEST]
# StandardSQL
FROM `myproject:TEST.TABLE_TEST`
I was wondering if Visual Studio accepts a custom query or can be parameterized to remove the quotes. If this doesn't help, could you please share the query that cause the error? I understand that there is a query option (I'm not familiar with Visual Studio) and it is not clear for me the exact moment when the tool returns the error, screenshot without sensitive information would be appreciated.
UPDATE:
You can review the following checkpoints that could help to verify that the Simba driver is correctly set up and it is not the cause of the reported error:
Installation. Check that you are using the last version of the driver. The last version usually contains improvements on the driver.
ODBC Configuration. For example, the Step 13 of the link you will be able to see a drop-down list with the datasets available and select one as the default. If you don't have issues is this step, then the issue could be in the tool that uses the ODBC connection.
Language Dialect. In here you case change between StandardSQL or LegacySQL as needed, for example, you can force your tool to use LegacySQL and use the characters [ and ] that I explained above.
Connection String. If your tool allows to use a string with the connection, you might want to use it and explicitly indicating the default Dataset (among other driver options).
I'm having difficulties in retrieving and displaying records from a table in a database. I'm using a MySql database and VB.NET 2012.
I'm getting the following error message
"End of statement expected"
Remove the space between Form2 and _Load. Your SQL statement is also broken, the AND being in blue shows this. You have your single and double quotes confusing it, the statement is being ended before the AND due to incorrect syntax. In any case, you should, probably, be using
"SELECT * FROM bigregdb WHERE regID = '"1"' OR regID = '"2"'"
I'm using RODBC to connect to a microsoft access database. Some queries work fine, but on one I keep getting the errors:
07002 -3010 [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
[RODBC] ERROR: Could not SQLExecDirect 'SELECT baseunit FROM archiverapp_common_units WHERE unitname = "ng/ml"'
I am using the 'sqlQuery' function to make the query. The SELECT statement given in the error is what I intend it to be and works when I copy-paste directly into Access. From what I've gathered looking at similar posts this frequently results from misspelling a column or table name, but everything seems correct here.
Figured it out - apparently the answer was to use single quotes instead of double quotes in the WHERE clause. Changing the query string in my R code from this
'SELECT baseunit FROM archiverapp_common_units WHERE unitname = "ng/ml"'
to this
"SELECT baseunit FROM archiverapp_common_units WHERE unitname = 'ng/ml'"
solves the problem.
I'm attempting to create a shared dataset in SSRS based on a DB2 query. The data source uses the DB2OLEDB provider.
When I enter the query directly as text, it executes correctly:
SELECT BTCH_DT FROM FMSCHEMA.TTRANS_HIST_DETL WHERE REC_NO = 13288604
However, when I click the expression button next to the query window, and enter the following:
="SELECT BTCH_DT FROM FMSCHEMA.TTRANS_HIST_DETL WHERE REC_NO = 13288604"
the query fails with
ILLEGAL SYMBOL "=?<ERR_STMT> <WNG_STMT> GET SQL SAVEPOINT HOLD FREE ASSOCIATE". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: SQLSTATE: 42601, SQLCODE: -104
it appears as if SSRS is trying to pass the expression itself to the DB2OLEDB provider instead of evaluating the expression and passing the results of that evaluation.
I've already checked out IBM's site:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/rsql0100.htm but the information provided for SQSLSTATE 42601 wasn't very helpful: "A character, token, or clause is invalid or missing."
Can anyone shed some light on this? Or point me in the right direction? Thanks!
I'm trying to create an SSIS 2008 Data Source View that reads from an Ingres database via the ODBC driver for Ingres. I've downloaded the Ingres 10 Community Edition to get the ODBC driver, installed it, set up the data access server and a DSN on the server running SSIS.
If I connect to the SQL Server 2008 Database Engine on the server running SSIS, I can retrieve data from Ingres over the ODBC DSN by running the following command:
SELECT *
FROM OPENROWSET( 'MSDASQL'
, 'DSN=IngresODBC;UID=testuser;PWD=testpass'
, 'SELECT * FROM iitables')
So I am quite sure that the ODBC setup is correct.
If I try the same query with SQL Server style bracketed identifier quotes, I get an error, as Ingres doesn't support this syntax.
SELECT *
FROM OPENROWSET( 'MSDASQL'
, 'DSN=IngresODBC;UID=testuser;PWD=testpass'
, 'SELECT * FROM [iitables]')
The error is "[Ingres][Ingres 10.0 ODBC Driver][Ingres 10.0]line 1, Unexpected character '['.".
What I am finding is that I get the same error when I try to add tables from Ingres to an SSIS Data Source View. The initial step of selecting the ODBC Provider works fine, and I am shown a list of tables / views to add. I then select any table, and try to add it to the view, and get "ERROR [5000A] [Ingres][Ingres 10.0 ODBC Driver][Ingres 10.0]line 3, Unexpected character '['.".
Following Ed Harper's suggestion of creating a named query also seems to be stymied. If I put into my named query the following text:
SELECT *
FROM "iitables"
I still get an error: "ERROR [5000A] [Ingres][Ingres 10.0 ODBC Driver][Ingres 10.0]line 2, Unexpected character '['".
According to the error, the query text passed by SSIS to ODBC was:
SELECT [iitables].*
FROM
(
SELECT *
FROM "iitables"
)
AS [iitables]
It seems that SSIS assumes that bracket quote characters are acceptable, when they aren't. How can I persuade it not to use them? Double quotes are acceptable.
I don't know a way to change the quoted identifier, but you may be able to get around this by creating a blank DSV (click through the DSV wizard without adding any tables) then, rather than adding the tables to the DSV directly, adding them as named queries (right-click the empty DSV and select "New Named Query".
This enables you control the text of the query yourself, and set your own identifiers.
(I'm making this suggestion based on SSIS 2005, but I think 2008 works in a similar way.)