I want to read data out by linked server in SSMS - ssms

Msg 7356, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "" supplied inconsistent metadata for a column. The column "" (compile-time ordinal 11) of object "" was reported to have a "DBCOLUMNFLAGS_ISLONG" of 128 at compile time and 0 at run time.
And O also got these message when I just want read out a single column and not that one which has some problem.
I try to use SELECT * from .... reading form and
SELECT * FROM OPENQUERY([], '') also.

Related

Select on field Date in OpenEdge

I am trying to make a select on the field 'Date' in the table UVT_DatesOfVersionsBOPos using the Microsoft SQL Server Management Studio (select * from openquery ([PROALPHA], 'select Date from PAVAR.PUB.UVT_DatesOfVersionsBOPos')
Unfortunately I get the following error message:
The OLE DB provider "MSDASQL" for the connection server "PROALPHA" has the message "[DataDirect] [ODBC Progress OpenEdge Wire Protocol driver] [OPENEDGE] Syntax error in SQL statement at or about" Date from PAVAR.PUB.UVT_DatesOfVersionsB "( 10713) ".
Msg 7321, Level 16, State 2, Line 1
Failed to prepare the select date from PAVAR.PUB.UVT_DatesOfVersionsBOPos query to run for the OLE DB provider "MSDASQL" for the linked server "PROALPHA".
I assume that SQL interprets the Date field as the Date function and therefore displays an error.
Does anyone of you know the correct syntax so I can get the field?
The syntax error is because of the fact that DATE is a reserved word in OpenEdge SQL. You can use keywords as identifiers in SQL statements only if you delimit them with double quotation marks.
Example 1: This generates syntax error as you described
SQLExplorer>select date from pub.cust1;
=== SQL Exception 1 ===
SQLState=HY000
ErrorCode=-210056
[DataDirect][OpenEdge JDBC Driver][OpenEdge] Syntax error in SQL statement at or about "date from pub.cust1" (10713)
Example 2: This works as we delimit reserved word with double quotes
SQLExplorer>select "date" from pub.cust1;
date
----------
Link to the documentation: https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dmsrf/openedge-sql-reserved-words.html

Strange error with ADO SQL string versus DoCmd.Execute

I'm trying to pass the following SQL string with ADO:
UPDATE ((JLE_Parcelas INNER JOIN ST_JLE_Municipios ON JLE_Parcelas.Cod_Parcelas_Municipio = ST_JLE_Municipios.Id_Municipios_Municipio) INNER JOIN ST_JLE_Provincias ON ST_JLE_Municipios.Cod_Municipios_Provincia = ST_JLE_Provincias.Id_Provincias_Provincia) INNER JOIN ST_JLE_Paises ON ST_JLE_Provincias.Cod_Provincias_Pais = ST_JLE_Paises.Id_Paises_Pais SET Parcelas_Alta_FechaFinal= NULL, Parcelas_Alta_FechaInicial= NULL, Parcelas_SIGPACNumPoligono= 20, Parcelas_SIGPACSuperficie= 79.9244, Parcelas_Observaciones='DDDDDEE', Parcelas_SIGPACNumParcela= 1, Parcelas_Contrato_FechaFinal= NULL, Cod_Parcelas_TipoProteccion= 1, Cod_Parcelas_TipoTenencia= 1, Cod_Parcelas_TipoRiego= 2, Cod_Parcelas_Agricultor= 4, Cod_Parcelas_Municipio= 195 WHERE Id_Parcelas_Parcela=7
but ADO returns Syntax error -2147217900 (systax error near '('.)
Notice I'm working with SQL Server database.
If I send the same string to Currentdb.execute, error dissapears and register is correctly saved, so I have two questions:
Can you tell me where is error in ADO?. I tried to find it, but it's impossible for me
is it better to use ado versus DoCmd, or vice versa?
Thanks in advance

saved data frame is not shown correctly in sql server

I have data frame named distTest which have columns with UTF-8 format. I want to save the distTest as table in my sql database. My code is as follows;
library(RODBC)
load("distTest.RData")
Sys.setlocale("LC_CTYPE", "persian")
dbhandle <- odbcDriverConnect('driver={SQL Server};server=****;database=TestDB;
trusted_connection=true',DBMSencoding="UTF-8" )
Encoding(distTest$regsub)<-"UTF-8"
Encoding(distTest$subgroup)<-"UTF-8"
sqlSave(dbhandle,distTest,
tablename = "DistBars", verbose = T, rownames = FALSE, append = TRUE)
I considered DBMSencoding for my connection and encodings Encoding(distTest$regsub)<-"UTF-8"
Encoding(distTest$subgroup)<-"UTF-8"
for my columns. However, when I save it to sql the columns are not shown in correct format, and they are like this;
When I set fast in sqlSave function to FALSE, I got this error;
Error in sqlSave(dbhandle, Distbars, tablename = "DistBars", verbose =
T, : 22001 8152 [Microsoft][ODBC SQL Server Driver][SQL
Server]String or binary data would be truncated. 01000 3621
[Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been
terminated. [RODBC] ERROR: Could not SQLExecDirect 'INSERT INTO
"DistBars" ( "regsub", "week", "S", "A", "F", "labeled_cluster",
"subgroup", "windows" ) VALUES ( 'ظâ€', 5, 4, 2, 3, 'cl1', 'ط­ظ…ظ„
ط²ط¨ط§ظ„ظ‡', 1 )'
I also tried NVARCHAR(MAX) for utf-8 column in the design of table with fast=false the error gone, but the same error with format.
By the way, a part of data is exported as RData in here.
I want to know why the data format is not shown correctly in sql server 2016?
UPDATE
I am fully assured that there is something wrong with RODBC package.
I tried inserting to table by
sqlQuery(channel = dbhandle,"insert into DistBars
values(N'7من',NULL,NULL,NULL,NULL,NULL,NULL,NULL)")
as a test, and the format is still wrong. Unfortunately, adding CharSet=utf8; to connection string does not either work.
I had the same issue in my code and I managed to fix it eliminating rows_at_time = 1 from my connection configuration.

Invalid object name 'sys.dm_exec_procedure_stats' error

I am trying to obtain the maximum time consumed by a stored procedure in my DB. I obtained a sample query from here to obtain the same using sys.dm_exec_procedure_stats. The same is posted below. Whenever I try to execute this query I get the error as
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.dm_exec_procedure_stats'.
Can you please let me know where I might probably be going wrong?
Below is the query used. No changes made.
SELECT TOP 10 d.object_id, d.database_id, OBJECT_NAME(object_id, database_id) 'proc name',
d.cached_time, d.last_execution_time, d.total_elapsed_time,
d.total_elapsed_time/d.execution_count AS [avg_elapsed_time],
d.last_elapsed_time, d.execution_count
FROM sys.dm_exec_procedure_stats AS d
ORDER BY [total_worker_time] DESC;
EDIT: Sorry for the blunder. Server is 2005.

BULK insert error

I am trying to BULK insert from .csv file and i get the following error:
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 23 (AR).
Msg 4864, Level 16, State 1, Line 4
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 3, column 23 (AR).
When i open the CSV file in Microsoft excel on row 2 column23 its just the number '0'.
So if i go manually in my database table and i insert the number 0 in the column AR it accepts it without any problems. I do not understand why this happens. Any help?
I assume your code looks something like this
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection))
{
// Create a reader somehow
IDataReader reader = new ... // <- Your problem will be here
bulkCopy.WriteToServer(reader);
}
In your reader you need to read the file according to it's type and encoding.
According to your file type you need to select the correct encoding from
System.Text.Encodig