Unexpected EOF from the server on SQL server - sql

I am running the following SQL query using the Navicat client for Mac:
SELECT
CREATE_TIME, EMAIL, NUMBER, SNID
FROM
LOG_DEVICE
WHERE
CID = 'T-MOB'
AND NUMBER LIKE '12345678%'
But when I do, I get Unexpected EOF from the server. I have tried adjusting the query to this:
SELECT
CREATE_TIME, EMAIL, NUMBER, SNID
FROM
LOG_DEVICE
WHERE
CID = 'T-MOB'
and it will run without issue. I'm guessing that it has something to do with the NUMBER column. I know the column has NULL and empty values, but it seems that the error happens at the end of the file.
What is causing this, and how can I handle it? Is there a way to handle the error so that I can complete the query?
UPDATE:
I am running SQL 2005. Not sure that makes a difference, but I figured I'd mention it.

In true Microsoft fashion, this issue was solved by running the exact same query from a PC, using HeidiSQL as the client.

Related

SQL Server FullTextSearch doesn't work properly for German

We have two SQL Servers and on both of them FTS is enabled and should be configured the same way. Both run with the same server version. The SQL Server we have problems with runs in Azure.
I also have checked the wordbreaker language versions with the following statement. Both have the version 14.0.4763.1000 installed for German (1031).
EXEC sp_help_fulltext_system_components 'wordbreaker'
On one server, we do not get results properly, even though the word we are searching for exists in the table. With the following query we don't get any results:
SELECT *
FROM vsTst vsTst
WHERE CONTAINS(vsTst.Content, 'FORMSOF(INFLECTIONAL, Einzelunternehmen) OR "Einzelunternehmen*"', LANGUAGE 1031)
But with the keyword "Einzelunternehm" instead of "Einzelunternehmen" we get the results we are looking for:
SELECT *
FROM vsTst vsTst
WHERE CONTAINS(vsTst.Content, 'FORMSOF(INFLECTIONAL, Einzelunternehmen) OR "Einzelunternehm*"', LANGUAGE 1031)
We have absolutely no clue what the issue is. Does anybody have the same problem or have any idea what we have done wrong?
Thx

Select column of other row in parameterized statement

I am a beginner in SQL, and I was having some trouble with special characters like parentheses and asterisks in user generated data. So far, I have mostly been using a lot of ad hoc methods of getting rid of these characters and they work well enough. Based on what I have read, I think paramaterized queries might be a more systematic way of getting around some of the problems that I have.
I have following query:
insert into midstep (street)(select street from addresses limit 10)
The column street in the table addresses has a lot of parantheses, asterisks etc. The code above works as expected. What I want to do is something like this:
prepare midstreet (text) AS insert into midstep (street)(select $1 from addresses limit 10);
execute midstreet ( street from addresses);
However, when I enter in that code I get the following error message:
ERROR: syntax error at or near "from"
SQL state: 42601
Character: 29
I have tried a bunch of variations on this code and read through the documentation on Prepare and Execute but always get error messages. Any help is appreciated!
EDIT: I forgot to mention, I am using postgresql 9.3 on and my os is Ubuntu. Please ask if you need any more information to help!
You do not need a parameter in your case, as you get your values using a sub-query. As a matter of fact, you cannot know the needed values on server-side. Parameters like that are needed if and only if you have some values defined on application level and you want to pass them to the database.

SQL Statement 'Missing Parameter' Fails On Single Machine

I'm using vb.net, and I've created a sql statement that I use with a OleDBConnection object. When I run my sql (below) the ExecuteReader throws an error (also below). The problem is that it works on the 50+ en-US machines that it's run on, but now I've got my first client in Germany, and it fails on their machine. I set my dev machine to German settings to try to replicate the issue, but it works just fine for me. I copied-over their exact data file and it works on my machine. So seemingly it has to do with it being a non en-US machine?
Here is the SQL statement:
SELECT Val(IIf(IsNumeric([Sequence]), [Sequence], '0')), *
FROM MyTable
ORDER BY SomeOtherField, 1
So in short, I want to order by the sequence column secondarily, but in the event that Sequence isn't numeric I'll just give it a '0' so that it allows the sort to take place based on the dynamic column '1' I am creating/selecting on-the-fly.
Here is the error on the German machine:
Fuer mindestens einen erforderlichen Parameter wurde kein Wert angegeben.
(Roughly translated: For at least one required parameter was not specified value)
Does anyone have any ideas as to what my issue might be? Thanks in advance for any assistance you can provide to me.
-Greg
This is just a guess. But, try replacing the iif() with a case statement:
SELECT (case when IsNumeric([Sequence]) = 1 then [Sequence]
else '0'
end),
mt.*
FROM MyTable mt
ORDER BY SomeOtherField, 1
I suspect that your other systems are using Access, and the German system is using SQL Server. SQL Server does not recognize iif.

SQL Permission Problem

I have having an issue with a SQL execution where I am getting an error message
-2147217843 Login Failed for user.
I am able to successfully open the connection to the database and execute select count(*) queries.
I am getting this error when I include fields.
In a separate application that uses the same fields I am able to retrieve the same data so seems to rule out column permissions.
The query coming back with no error is:-
SELECT tbl_PersonalDetails.SystemID
FROM tbl_PersonalDetails
WHERE tbl_PersonalDetails.Title IS NOT NULL
And tbl_PersonalDetails.HospitalNumber IS NOT NULL
AND tbl_PersonalDetails.SiteID = 1
The query coming back with the error is:-
SELECT DISTINCT tbl_PersonalDetails.Title,tbl_PersonalDetails.HospitalNumber
FROM tbl_PersonalDetails
WHERE tbl_PersonalDetails.SiteID = 1
ORDER BY tbl_PersonalDetails.Title,tbl_PersonalDetails.HospitalNumber ASC
This is not specific to these particular queries, in the first query where we are just doing a count I always get a count back with no issue, when I try to request fields such as in the second I always get the Login Error.
Your problem isn't in the SQL queries you've posted. They would either all fail or all succeed based on the information given.
Your problem is your calling/client code. Sounds like you're using Classic ASP ("recordset....adodb connection").
Double check that your ASP code is using the proper connection strings.
To prove this, run any of these queries in SQL Server Management Studio. Connect using the credentials that your connection string contains.

SQL query giving wrong result on linked server

I'm trying to pull user data from 2 tables, one locally and one on a linked server, but I get the wrong results when querying the remote server.
I've cut my query down to
select * from SQL2.USER.dbo.people where persId = 475785
for testing and found that when I run it I get no results even though I know the person exists.
(persId is an integer, db is SQL Server 2000 and dbo.people is a table by the way)
If I copy/ paste the query and run it on the same server as the database then it works.
It only seems to affect certain user ids as running for example
select * from SQL2.USER.dbo.people where persId = 475784
works fine for the user before the one I want.
Strangely I've found that
select * from SQL2.USER.dbo.people where persId like '475785'
also works but
select * from SQL2.USER.dbo.people where persId > 475784
brings back records with persIds starting at 22519 not 475785 as I'd expect.
Hope that made sense to somebody
Any ideas ?
UPDATE:
Due to internal concerns about doing any changes to the live people table, I've temporarily moved my database so they're both on the same server and so the linked server issue doesn't apply. Once the whole lot is migrated to a separate cluster I'll be able to investigate properly. I'll update the update once this happens and I can work my way through all the suggestions. Thanks for your help.
The fact that LIKE operates is not a major clue: LIKE forces integers to string (so you can say WHERE field LIKE '2%' and you will get all records that start with a 2, even when field is of integer type). Your incorrect comparisons would lead me to think your indexes are corrupt, but you say they work when not used via the link... however, the selected index might be different depending on the use? (I seem to recall an instance when I had duplicate indexes and only one was stale, although that was too long ago to recall the exact cause).
Nevertheless, I would try rebuilding your index using the DBCC DBREINDEX (tablenname) command. If it turns out that doing so fixes your query, you may want to rebuild them all: here is a script for rebuilding them all easily.
Is dbo.people a table or a view? I've seen something similar where the underlying table schema had been changed and dropping and recreating the view fixed the problem, although the fact that the query works if run directly on the linked server does indicate something index based..
Is the linked server using the same collation? Depending on the index used, I could see something like this perhaps happening if the servers were not collation compatible, but the linked server was set up with collation compatible (which tells Sql Server it can run the query on the remote server).
I would check the following:
Check your definition on the linked server, and confirm that SQL2 is the
server you expect it to be
Check and compare the execution plans both from the remote and local servers
Try linking by IP address rather than name, to ensure you have the proper machine
Put the code into a stored procedure on the remote machine, and try calling that instead
Sounds like a bug to me - I;ve read of some issues along these lines, btu can't remember specifically what. What version of SQL Server are you running?
select * from SQL2.USER.dbo.people where persId = 475785
for a PersID which fails how does:
SELECT *
FROM OpenQuery(SQL2, 'SELECT * FROM USER.dbo.people WHERE persId = 475785')
behave?