SQL Server Query written in a one format works, but when using a different format returns Error 0?

anhgbhbe  于 2023-11-16  发布在  其他
关注(0)|答案(1)|浏览(87)

I am using the query below to query the data container STRFL from a SQL Serverless Pool:

-- This query format doesn't work with GRDCFG
SELECT
    TOP 10 TAF_Id
FROM OPENROWSET (
    'CosmosDB', N'account=ACCOUNT;database=DATABASE;region=REGION;key=PRIMARYREADONLYKEY',STRFL
) AS Docs

This query works as intended. However, when I change the container to GRDCFG, I get the following error:

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)

The container GRDCFG exists in the database (the spelling of the object name is correct - literally just changed the container name in the query) so I don't understand why SQL is returning the error.

Normally, below is how I would query GRDCFG, but I would like to try the query format above (and understand why it isn't working that way):

-- This query format works with GRDCFG
SELECT TOP 10 TAF_Id
FROM OPENROWSET(
    PROVIDER = 'CosmosDB',
    CONNECTION = 'Account=ACCOUNT;Database=DATABASE',
    OBJECT = 'GRDCFG',
    SERVER_CREDENTIAL = 'CREDENTIAL'
) WITH (
    TAF_Id VARCHAR(10)
) AS Data

Both are using OPENROWSET but the second query requires me to define the fields I need. In this particular use-case, I need to get the data from all the columns from the GRDCFG container without defining the fields, hence the need to use the first query format.

Anyone know what is causing this behavior?

vshtjzan

vshtjzan1#

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)

The transit error generally comes for timeout or if query doesn't complete in particular time for larger dataset.

Fo this you can tr adding additional parameter timeout to the linked service.

maxIdleTimeMS : 60000000

I need to get the data from all the columns from the GRDCFG container without defining the fields.

To get all fields you can use this query in below format.

SELECT  TOP  100 *
FROM  OPENROWSET(​PROVIDER = 'CosmosDB',
CONNECTION = 'Account=cosmosdb-account;Database=daytabase-name',
OBJECT = 'container-name',
SERVER_CREDENTIAL = 'credential name'
) AS [container-name]

相关问题