Export SQL Server linked server table with 334449 rows - sql

I want to export the data from a table from linked server. The table has over 300,000 rows.
When I run this query:
SELECT *
FROM [LSERVER].[LTechnologies].[Connector].[MASD]
I get an error:
OLE DB provider 'MSDASQL' for linked server 'LSERVER' returned data that does not match expected data length for column '[LSERVER].[LTechnologies].[Connector].[MASD]'. The (maximum) expected data length is 8000, while the returned data length is 8448.
The source is NetSuite linked to MS SQL as ODBC Data Source.
Is there any way to work around this limitation?
Thanks

Is there any way to work around this limitation?
The typical workaround is to use OPENQUERY to send a "passthrough" query to the target system and ask it to perform type conversions to the types that actually work.

Haim, it sounds like a built limitation limiting varchar or nvarchar to 8K characters. I have seen this a couple times but never seen anyone beat it - normally we just exclude the column. However if it's worth the time, you could find the column and do a LEFT([column], 7999) to see if you can at least get most of the data back. Hope it helps.

Related

Query remote oracle CLOB data from MSSQL

I read different posts about this problem but it didn't help me with my problem.
I am on a local db (Microsoft SQL Server) and query data on remote db (ORACLE).
In this data, there is a CLOB type.
CLOB type column shows me only 7 correct data the others show me <null>
I tried to CAST(DEQ_COMMENTAIRE_REFUS_IMPORT AS VARCHAR(4000))
I tried to SUBSTRING(DEQ_COMMENTAIRE_REFUS_IMPORT, 4000, 1)
Can you help me, please ?
Thank you
No MSSQL but in my case we were pulling data into MariaDB using the ODBC Connect engine from Oracle.
For CLOBs, we did the following (in outline):
Create PLSQL function get_clob_chunk ( clobin CLOB, chunkno NUMBER) RETURN VARCHAR2.
This will return the the specified nth chunk of 1000 chars for the CLOB.
We found 1,000 worked best with multibyte data. If the data is all plain text single byte that chunks of 4,000 are safe.
Apologies for the absence of actual code, as I'm a bit rushed for time.
Create a Oracle VIEW which calls the get_clob_chunk function to split the CLOB into 1,000 char chunk columns chunk1, chunk2, ... chunkn, CAST as VARCHAR2(1000).
We found that Oracle did not like having more than 16 such columns, so we had to split the views into sets of 16 such columns.
What this means is that you must check what the maximum size of data in the CLOB is so you know how many chunks/views you need. To do this dynamically adds complexity, needless to say.
Create a view in MariaDB querying the view.
Create table/view in MariaDB that joins the chunks up into a single Text column.
Note, in our case, we found that copying Text type columns between MariaDB databases using the ODBC Connect engine was also problematic, and required a similar splitting method.
Frankly, I'd rather use Java/C# for this.

invalid data is getting inserted in table in sql server database

I faced a situation and also searched for it in the internet but could not be able to get any solution.
Problem
My sql server table has 15000 records. It has several columns.
Among all the records, the 'Email ID' column of one record is storing value along with an unidentified character at the beginning. (Please refer to picture attached)
What I want
I want to get rid of that character using sql query. I am using sql server 2012 version.
I tried with 'replace()' and 'patindex()'. I even tried 'stuff' function.
But, its not working. Instead, when I am fetching the data using query, it is showing that typical character.
Please help me with some ideas. If I need to do some settings in database or table, I am ready for that.
Thanks.

Simba Mongo ODBC driver: returned data that does not match expected data length

We are using Simba Mongo ODBC driver to connect to Mongo database and make sql queries. I tested connection on Linux using isql and was able to perform queries.
When my client tried to connect to Mongo through Microsoft SQL Server Management Studio he received the following error:
OLE DB provider 'MSDASQL' for linked server 'mongo' returned data that does not match
expected data length for column '[MSDASQL].contributorComposite__0__biographicalNote'.
The (maximum) expected data length is 255, while the returned data length is 290.
I've never worked with this application. Have you got any idea where I can control expected data length?
Linked Server is very picky about metadata and the data that is returned, in general you're more likely to encounter problems if your defined metadata doesn't match exactly what is expected when using it vs. using other applications.
What's happening in this case is that you're retrieving data with a string column defined. The data in the string column has a length of 290, but the driver is reporting a length of 255. This is because MongoDB doesn't return metadata about the length of any specific field as it is a schema-less data source. The driver instead uses a default for reporting lengths of string columns, which by default is set to 255. You can change this by opening the Configuration Dialog for the DSN, going to the Advanced Options, and changing the Standard string column length from 255 to something larger, like 512. This should allow Linked Server to behave properly unless your data exceeds 512 bytes, in which case you should simply adjust this to a larger appropriate value.
I found this answer here: One way to get around this problem is to construct your SQL statement, such as:
declare #myStmt varchar(max)
set #myStmt = 'select * from my_collection'
EXECUTE (#myStmt) AT MongoDB_PROD_mydb
I did try it myself on a linked SQLite server and it worked but the strange part is that on longer entries the text get cut off somewhat randomly. I have not figured this part out yet - it might have something to do with SQLiteODBC driver I'm using.
But the error of "expected data length" is handled.
Michael

Return Active Directory jpegPhoto attribute in LDAP SQL query from SSMS in SQL Server

I've hit a brick wall on this issue and I can't seem to find or work out what is going wrong or find an answer to my problem ... I'm totally new to querying Active Directory, so I am hoping I've not done something that will warrant slapping my forehead when points me towards the solution!
So, I've uploaded images into both thumbnailPhoto and jpegPhoto and I can see in ADSI Edit that these do have a value.
I've set up a linked server (named ActiveDirectory) on our 2008 R2 Database Server and I can successfully query this and return results. If I run the query below, it returns the values fine, but once I uncomment the jpegPhoto line (commented out in the code below), I get the error ...
Cannot get the data of the row from the OLE DB provider "ADSDSOObject" for linked server "ActiveDirectory". Could not convert the data value due to reasons other than sign mismatch or overflow.
The query runs correctly with jpegPhoto uncommented if the contents of that field are never populated in the returning result set.
SELECT
objectGUID
,cn
,thumbnailPhoto
-- ,jpegPhoto
FROM OpenQuery (
ActiveDirectory,
'SELECT
objectGUID
,cn
,thumbnailPhoto
,jpegPhoto
FROM ''LDAP://XXXXX/OU=XXXXX,DC=XXXXX,DC=XXXXX,DC=com''
') AS AD
WHERE cn = 'username'
It seems strange to me that the result can be returned from the OpenQuery (I've tried OpenRowset to no avail), it fails outside of that it seems.
I have also tried all manner of CAST and CONVERT, but I'm at a loss now as to how I can actually get the contents of this field returned in my query (which I am just attempting to run in SQL Server Management Studio.
Has anyone come across this issue and overcome it?
I'm definitely hoping so!!
Thanks in advance!!
Gannon
Old issue I know but for those finding this on the googles.
As far as I can tell, for thumbnailPhoto, OLE DB Provider for Microsoft Directory Services is limited to 4k field sizes. This means if you upload a teenytiny photo, it works.
For jpegPhoto, there is a difference in the field type -
thumbnailPhoto is single valued and has a upper-Range of 102400 bytes.
jpegPhoto on the other hand is multivalued and doesn’t enforce an upper-Range
And, according to other pages on the internet -
The ADSI provider for SQL Server is rather limited - not supporting multi-valued attributes is one of those limitations.

Create delimited string from a row in stored procedure with unknown number of elements

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row?
I'm pulling one row at a time from different tables and am going to store them in a column in another table.
A simple SQL query can't do anything like that. You need to specify the fields you are concatenating.
The only method that I'm aware of is to dynamincally build a query for each table.
I don't recall the structure of MSSQL2000, so I won't try to give an exact example, maybe someone else can. But there -are- system tables that contain table defintions. By parsing the contents of those system tables you can dynamically build the necessary query for each source data table.
TSQLthat writes TSQL, however, can be a bit tricky to debug and maintain :) So be careful how you structure everything...
Dems.
EDIT:
Or just do it in your client application.