I am trying to do a very simple sql select statement from a MySQL database:
Dim lDatabase As Database = DatabaseFactory.CreateDatabase("FTP")
lSqlString = String.Format(CultureInfo.CurrentCulture, "SELECT monthends.web_usr FROM monthends")
lDBCommand = lDatabase.GetSqlStringCommand(lSqlString)
lUsers = lDatabase.ExecuteDataSet(lDBCommand)
And on the execute dataset line I receive the following ODBC Exception:
In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.
I don't get it. This is the simplest of simple sql statements and it has all worked just fine in the past, why doesn't this work anymore???
Thanks in advance!
What was going on was that there was an incorrect version of the MySQL ODBC 3.5xx driver installed. I contacted the DB Admin and got the correct version, it all works now as it should.
Related
This code works when the connection is made to an accdb database:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From Klantgegevens Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
But the code below gives the error about the Idx parameter when the connection is made to a SQL server database that has a table with the same structure:
Dim customer = connection.Query(Of Klantgegevens)("Select Actief,Onderhoudscontract From [dbo.Klantgegevens] Where Klantnummer=#Idx", New With {.Idx = customerId}).SingleOrDefault
What is going wrong here? I had hoped that by using Dapper I would be able to write database agnostic code. But it seems that is not the case!
If you are using an ODBC/OLEDB connection, then my first suggestion would be: move to SqlClient (SqlConnection). Everything should work fine with SqlConnection.
If you can't do that for some reason - i.e. you're stuck with a provider that doesn't have good support for named parameters - then you might need to tell dapper to use pseudo-positional parameters. Instead of #Idx, use ?Idx?. Dapper interprets this as an instruction to replace ?Idx? with the positional placeholder (simply: ?), using the value from the member Idx.
This is also a good fix for talking to accdb, which has very atypical parameter usage for an ADO.NET provider: it allows named parameter tokens, but all the tokens all replaced with ?, and given values from the positions of the added parameters (not via their names).
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 am creating a SSIS package that involves a where clause as:
WHERE effectiveDate >= #effectiveDate
Therefore, I defined #effectiveDate at the package level so that I can pass in value from a sql command using a different connection.
At the OLE DB source, I selected 'SQL command', and put the code as
Select ... FROM ...
WHERE effectiveDate >= ?
When I click on the 'parameters', an error appears:
'Parameters cannot be extracted from the SQL command. blablabla... use "SQL command from variable"...'
I am trying to avoid using SQL command from variable and try to locate the problem since I should be able to pass in variable.
Can anyone help? Thanks a lot!!
When building an OleDbCommand, you should actually name the parameter as the package is expecting, such as
OleDbCommand cmd = new OleDbCommand( "select ... from... where... eff > #yourPkgPameterName");
cmd.Parameters.AddWithValue( "#yourPkgPameterName", whateverValueToSend );
It's been a while for SQL-based parameters and don't remember if the AddWithValue() method is expecting the "#" or not... may need to try without it if it fails.
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.)
I have a lot of services which query the database. All of them work fine but one service calling a stored procedure gives me following error:
Could not find server 'dbo' in
sys.servers. Verify that the correct
server name was specified. If
necessary, execute the stored
procedure sp_addlinkedserver to add
the server to sys.servers.
I have not idea why all the other stored procedures work fine and this one not...
By the way, I use SubSonic as data access layer.
Please run select name from sys.servers from the server which you mentioned as default server in configuration file.
Here in name column values should match with your server names used in the report query.
e.g serverXXX.databasename.schema.tablename
serverXXX should be there in the result of select name from sys.servers otherwise it gives error as got.
It sounds like there is an extra "." (or two) in the mapping - i.e. it is trying to find server.database.schema.object. Check your mapping for stray dots / dubious entries.
Also make sure that the server name matches what you think it is. If you rename the host that SQL Server is running on, you need to rename the SQL Server, too.
http://www.techrepublic.com/blog/datacenter/changing-the-name-of-your-sql-server/192
I had another issue with the same exception so I'll post here if someone stumble upon it:
Be careful if you specify the server name in synonyms. I had a different server name on my staging machine and production and it caused the same 'cannot find server'-error.
(Guess you shouldn't use synonyms that much anyway but it's useful in some migration scenarios)
In my case i was facing same issue with following ,
SqlCommand command = new SqlCommand("uspx_GetTemplate", connection);
but after adding square bracket to stored procedure name it get solved.
SqlCommand command = new SqlCommand("[uspx_GetTemplate]", connection);