Query with SQL Server 2008 R2 with FireDAC - sql-server

I'm new to Firedac but not with Delphi
I can make a connection with SQL Server, and when I connect, there is no problem. I get connection OK. It works with code, with the wizard and with the FireDAC explorer.
The name of the database is :
C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\MSSQL.1\MSSQL\DATA\3410b539-431f-4dff-ad0d-a574d1b13498.MDF
I'm stuck with a simple query.
SELECT *
FROM Account;
This query works from within the FireDac explorer but not from my program, I'm getting the following error:
[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Could not find server 'C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\MSSQL' 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'm also also getting the same error, when I try to do it from the UI within Delphi.
To try the query, I dropped onto the form a TFDQuery, the connection property was set automatically to the unique connection on the form. Then I set the query with the query editor, I get the error when I click on execute.
With code it like this :
FDConnection1.Connected := true;
FDQuery1.Close;
FDQuery1.SQL.Text := 'select * from Account;';
FDQuery1.Active := True;
When I debug the program, I get the error when setting the query active.
I see that the name of the DB is not complete in the error message. But it's complete in the component settings
Please advise,
I tried some extra test :
If I run the query from the UI editor (double-clicking on the FDConnection, Tab SQL Script), type the query, it works :-).
But when I try to do it on the FDQuery component, with the connection assigned to previous FDConnection, I get the same error. It' like some parameters are missing.

You are using the location of the SQL data file, instead of the name of the SQL Database.
If you do not know the name you can use the wizard to try and find it.
(Sorry could not add comments yet. This is also mentioned by Jens in the comments)
Update: if that is really the name, try enclosing it in [ ].

I got this response from an Embarcadero engineer:
The problem is not in FireDAC, but in SQL Server ODBC driver
SQLPrimaryKeys function. It fails to work with a catalog name
containing a dot. FireDAC uses this function to get primary key fields
for a result set, when fiMeta is included into FetchOptions.Items. So,
as a workaround / solution, please exclude fiMeta from
FetchOptions.Items.

Related

Cannot run JSON_VALUE in SQLite database (.db file) in SQL Server Management Studio

I want to update some JSON data in SQLite database (.db file) and I met a problem.
I work in Microsoft SQL Server Management Studio where I added SQLite/SQL Server Compact Toolbox through Visual Studio Extensions. I'm succesfully able to connect to this file and I'm also able to run a query on this database (create table, insert data etc.). The only problem is that a table I want to update has a JSON column and I need to use the JSON_VALUE function to get some data from that column. And when I run SELECT JSON_VALUE([data]) FROM myTable, I get an error message:
ErrorCode : 1
Message : SQL logic error
no such function: json_value
Result : Error
for a query SELECT sqlite_version I got a result 3.24.0.
What am I doing wrong? What should I add to system to make this thing working? In standard SQL everything is working fine. SSMS is version 14.0.
I also tried programs "DB Browser for SQLite" and "SQLiteStudio" and also did the same example in Visual Studio and got exactly the same error.
Any hints (please step by step, I'm totally new to SQLite) would be appreciated.

Using Parameters when connecting SQL Server query to Excel

I've done this numerous times in the past when connecting Access queries to Excel, but now when I try and do it with a SQL Server query, I get an error message of
[Microsoft][ODBC SQL Sever Driver]Invalid parameter number
before I can even assign the parameter a value.
Once I got this error message I started to look around online for some answers, and I came across this article here. I followed these steps, which is essentially what I was doing anyway, and I still get the same error. The article is a few years old, so I'm not sure if things have changed since the release of Excel 2016 (my current version).
Is this something that cannot be done anymore without using VBA?
Just to summarize my steps, this is what I have done:
From Other Sources > From Microsoft Query
Select Database from MS Query Prompt > Click SQL button
Paste SQL > Click Return Data Button
Click Definition in Connection Properties window> Swap criteria code with ? in Command Text
Click OK
It looks as though I may have found the issue. When doing the initial connection through MS Query, you are asked to select the data source. Apparently there are two SQL Server options, one named SQL Server and another named SQL Server Native CLient 11.0. Originally I chose SQL Server, after trying numerous ways to fix this issue, I deleted the data source completely from MS Query, and started over, this time I chose SQL Server Native Client 11.0 and it worked exactly as it should. I'm not entirely sure what the difference between the two are, but it seems to have made the difference.
I had this issue as well and it turns out that because I had included square braces around the procedure I wanted to execute it seemed to think it was a parameter. e.g.
exec dbo.[myproc] #foo=?
just changing to...
exec dbo.myproc #foo=?
worked fine.
I think behind the scenes the params are being put in an array and square brackets in the sql is confusing it. Hope this helps. It may well be that sql native client 11 doesn't handle the params in the same way so you bypass this problem.

Entity Framework Data First - Invalid Object Name dbo.TableName

sup?
I got this problem wich has been slowing down my production a lot, hope u guys can give me any tip on how to solve it....
I'm currently using EF6 and a custom ConnectionString with a connectionString builder class that reads and external xml file.
My database is all set up and running in SQL 2010 and Management Studio ok, but whenever I generate the edmx file, it generates the class mappings okay, I've compared the original ConnectionString to my ConnectionString Builder they're the same, changed the :base to receive a custom ConnectionString, all set.
But when I try to save changes it doesn't find the table object, I have deleted it, created again from the start, still same "Invalid database object Dbo.TableName" error.
Does any one have a clue on this?
Thanks in Advance!
This error is not coming from Entity Framework but directly from the database.
Use SQL Profiler and include in the trace the "DatabaseName" and "ServerName" and you will find out it's not the same as your expected.
The only other options which this issue happen is if your "tableName" is not the same as the table name in SQL, so run the SQL from the SQL Profiler directly into SSMS.

SQL Server 2012 error: object reference not set to an instance of an object

I use SQL Server 2012 and I have some databases on it. The problem is I suddenly get an error saying,
object reference not set to an instance of an object
I get this error when:
Going to write a new query
Select previously entered data by right click the table name ->
Select top 1000 rows
What I can do without getting error message:
Log into my instance successfully using both Windows Authentication mode and SQL Authentication mode.
Edit the table data by right click the table name -> Edit top 200 rows
Create a new database
I'm using:
Microsoft SQL Server Management Studio: 11.0.3128.0
Microsoft .NET Framework: 4.0.30319.34014
Operating System: Windows 8.1
Here are some snapshots of the error.
Please give me a solution to fix this problem. Your help will be highly appreciated.
I fixed the problem by running SSMS as administrator.
I could solve the error.
Repair the SQL Server.
Go to Add/remove programs Microsoft SQL Server 2012(x64) -> Uninstall/Change -> Repair.
Select the instance that you want to repair here.
For me, after repairing the instance, the error was solved.
Thanks for all who spent their valuable time to reply my question.
I got the same error message. Problem was 0 bytes free on the C: drive.
Its may be late, but i get the same error in SQL SERVER 2016, i resolved it by assigning full access to the back up folder.
I faced the same error once in my project. This is purely due to SSMS(sql client) is corrupted. Just for cross check that server is fine and client is corrupted, try to connect to the sql-server in this machine from any other server if you have access and query the tables. If it returns data, just uninstall and reinstall the client(ssms) to solve the issue
Thanks
I got the same error for SQL 2016 and the only solution for me was to completely uninstall (in appwiz.cpl) all entries Visual Studio + SQL. Then I executed VisualStudioUninstaller and I reinstalled SQL and after Visual Studio.
I got the same message when I try to alter table to add new column . Issue is I haven't enclosed data types using '[' datatype ']' . Its Real data type. But It got fixed when I enclosed in using square braces.
My solution for this was to extract the csv file with the python library pandas rather than saving it with Excel. Further, I removed columns that I didn't need as a few columns caused formatting errors during the import.
For those who are unable to modify their SQL configuration due to administrative restrictions at work:
I was able to open a new query page by creating a SQL Server Scripts project and adding a new query through the solution explorer
I got the message after deleting a database. The database was gone, so I moved on.

MS SQL Server 2008 Link server query says "Invalid Object Name" but still works

The following query has a red squiggly underlining for the server through to the table this bit [OtherServer].[UAT_DB].[dbo].[profileTable] and when hovering says Invalid Object Name, but interestingly if I execute the line it returns the correct records from the linked server table:-
select * from [OtherServer].[UAT_DB].[dbo].[profileTable]
Intellisense in sql server works fine for queries on the same server. But when it comes to run a query on a remote server then it doesn't really know how to deal with it.
For certainty intellisense will not work with a remote server that has a version that does not support intellisense. For instance if the remote database has a compatibility level of 80(SQL 2000).
Refreshing the local intellisense cache might fix it.
Whilst in a query window, either:
Press Ctrl + Shift + R
Go to the Edit menu -> Intellisense -> Refresh Local Cache
I had to use an ALIAS in order for it to work.
Example:
select * from [OtherServer].[UAT_DB].[dbo].[profileTable] myalias
where myalias.profileid = 1

Resources