How to fix this CLI error in SAS? - sql-server

I've been getting this error when I try to drop, delete, truncate a table in SQL Server using SAS:
ERROR: CLI error trying to establish connection: [DataDirect][ODBC SQL
Server Wire Protocol driver]Error parsing connect string at
offset 74.
This is the code that's causing it:
proc sql;
connect to odbc(noprompt="Driver={DataDirect 6.1 SQL Server Wire Protocol};99.999.999.99;Port=1433;Database=AAA;Uid=sqluser;Pwd=sqlserverpass;");
execute (drop table dbo.BBB_SUMMARY) by odbc;
disconnect from odbc;
quit;
Append works okay. Does anybody know how to solve this?

"Error parsing connect string at offset 74." is a pretty big clue.
Presuming 99.999.999.99 in your connection string is the ip address of your SQL Server, you might need to change that to HOST=99.999.999.99.
See DataDirect docs
Couldn't speculate why the same seemingly malformed connection string would work for append.

Related

What is causing this bizarre error message when opening my Access database on another PC?

The error is following:
The ODBC connection string is obviously wrong and not in the right format. But I don't understand where Access is getting it from! The correct and working connection string (string saved in the Access database via the Linked Table Manager) is below. It should be noted that my colleague is opening the compiled .accde file in Access Runtime and does not have Office installed on his computer. The data tables are in SQL Server. Another colleague, who does have Office installed (presumably) got it to open with no problem.
This is the proper connection string which is used in Linked Table Manager to link the tables to SQL Server:
"DRIVER=ODBC Driver 17 for SQL Server;SERVER=hgws19.win.hostgator.com;UID=*******;PWD=********;Trusted_Connection=No;APP=Microsoft Office;DATABASE=mypubid_usergamelog;"
What I can't understand is why this other string in the error message is being used instead of the correct one in Linked Table manager. Anyone have any ideas how to troubleshoot this?

How to add Sybase SQL Anywhere DB as linked server to MS SQL Server properly

I used the Microsoft OLE DB Provider for SQL Anywhere to create a linked server, it shows remote databases and tables, I can read data, but writing data seems to work only using OPENQUERY() and when doing the connection_authentication using EXEC ... AT ... directly in the script.
How can I have the SQL Server do the authentication automatically when opening a connection?
How can I make normal write operations work without OPENQUERY()?
Sorry for not adding detailed error messages, I will add them later maybe, when I have access to the server again... But they were not meaningful anyway, i.e. when the weird authentication was missing, it just said "could not insert" or "failed" instead of indicating any authentication issue.
How to get the real error messages that come from Sybase?
Details:
SAP Sybase SQL Anywhere 16 (OEM Authenticated Edition) <-> MS SQL Server 2014
EXEC 'SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=''Company=...''' AT linkedserver
INSERT INTO OPENQUERY(linkedserver, 'SELECT column FROM table WHERE 0=1') VALUES ('')
...that's not nice.
Even more details:
This is how I created the linked server
This is the authentication I'm talking about

Pdo mssql error messages

I'm using pdo through freetds driver to connect to Mssql database and I'd like to output detailed sql errors against the generic one.
E.g. I got this generic error from PDO
SQLSTATE[HY000]: General error: 547 General SQL Server error: Check messages from the SQL Server [547] (severity 16) [(null)]
But SQL client gives me more details, and I'd like to get them in php. E.g. in the same case:
The DELETE statement conflicted with the REFERENCE constraint "FKORDINICLIENTI". The conflict occurred in database "dbo.Ordini", column 'IDCliente' of database "dbName".
I've already read this old note PHP / PDO / MSSQL how to get error informations?
and I'd prefer to avoid an additional query.
Thanks.
I think code doesn't matter, I know what's wrong in sql, just wanted to access the second code block from php.
I solved using odbc driver instead of freetds.

Having trouble connecting to SQL Server database from VBA using ADO connection

I want to connect to a SQL Server database without using DSN. I'm receiving an error when trying to connect to said database. The error is
Run-time error '-2147467259 (80004005)': [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
My connection string looks like this:
"ODBC;DRIVER=SQL Server;SERVER=lokdb; UID=secret;PWD=secret;APP=Microsoft Open Database Connectivity;WSID=" & Environ$("COMPUTERNAME") & ";Network=DBMSSOCN;Trusted_Connection=Yes;DATABASE=EDMS-Lok"`
I am able to connect to the default database on the server with the credentials specified if I remove the DATABASE=EDMS-Lok parameter from the connection string, however I don't then seem to be able to "find" the EDMS-Lok database. E.g. if I try using
SELECT * FROM EDMS-Lok.dbo.eng_dwg
I get an error message
Run-Time error '-2147217900 (80040e14)': [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '-'
(eng_dwg is a valid table)
When I connect without specifying a database, the .DefaultDatabase property of the ADO connection object returns "020" which I don't even see as an available database on that server??
When connected, if I use SELECT name FROM sys.databases I'm able to get a list of the databases available. They are:
010
100
500
EDMS-Lok
Master
msdb
MSLLockDB
pubs
tempdb
I got it working using DSN, but I don't want to use DSN.
Not sure what is wrong here??
I would say the problem is that you mix up the authentication models. You provide user + password but also you have configured trusted connection = yes. I'm not sure how ADO works in that case but I would assume that it doesn't use the configured user and connects with the windows account. Delete the trusted connection parameter in the connection string and try again.
OK, credit for this answer should go to Dee and Sam who commented on the original question, however I can't mark a comment as the answer, so here it is:
Needed to wrap the database name in square brackets [ ] ... like this DATABASE=[EDMS-Lok] - (credit to DEE)
I first tried wrapping the database name in the connection string i.e. DATABASE=[EDMS-Lok] and this did not work (same error). However, if I connect without specifying the database, I'm able to access the table using SELECT * FROM [EDMS-Lok].dbo.eng_dwg
It didn't work in the connection string because the string is not T-SQL code. To get it to work, you may need to figure out how to escape the dash character. – (credit to SAM)
I've tried single and double quotes, backslash, square brackets, parentheses and curly brackets and nothing seems to work to escape the hyphen in the database name within the connection string. But, since I can now access the database and the tables I need, which was the original question, I wanted to mark it as answered.

SQL Server queries xls file worked yesterday(I swear), now refuses to. 0.o

Hey all, the following select statement used to correctly query an Excel spreadsheet on a 64bit SQL Server 2008 R2, and now provides me with an error.
SELECT
MPNCode, Supplier, Stock , Price, Manufacturer, [Description]
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;Database=C:\inetpub\wwwroot\nCompass\Products\Import\SupplierProducts.xls;HDR=YES',
'SELECT * FROM [Sheet1$]') WHERE MPNCode IS NOT NULL
The error I get is.
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked
server "(null)" returned message
"Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"Microsoft.ACE.OLEDB.12.0" for linked
server "(null)".
I've tried restarting everything and googled the thing to death - somehow something has happened that is preventing this from working.
The file-path/file-name is correct because when I change the path I get a different error message.
Ad-hoc connections are enabled from the surface manager - after this I'm stumped at what the issue could be.
Any help will be very much appreciated.
Is the linked spreadsheet opened on the desktop? What happens if you create a new sheet in the same folder and try to open it instead?
I think SQL Server needs to access to TEMP folders to copy or create some files.
If the folder does not exist or ther SQL Service account does not have enough permission to access the folders, you'll get the exception.
Run Procmon.exe on the server and execute the query again. You can see what's happening and where the SQL Server wants to access.

Resources