Sqlcmd ошибка microsoft odbc driver 11 for sql server

Обновлено: 05.07.2024

This is my configuration. I have a redhat 6.6 x64, I need to use it to connect to a remote Ms SQL 2008 database server via odbc/jdbc. I have another setup with Windows 2008r2 as client connection to the same MS SQL 2008 server so I knew the ip, password, connectivity are setup correctly on the SQL server side.

I had successfully install the driver manager and odbc drivers for Microsoft ODBC Driver 11 For SQL Server for Linux.

the result of command odbcinst -q -d -n "ODBC Driver 11 for SQL Server" is

[ODBC Driver 11 for SQL Server]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so
Threading=1
UsageCount=1

The result of command /usr/bin/odbcinst -q –j is

unixODBC 2.3.0
DRIVERS. /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES. /etc/ODBCDataSources
USER DATA SOURCES. /root/.odbc.ini
SQLULEN Size. 8
SQLLEN Size. 8
SQLSETPOSIROW Size.: 8

the result of bcp -v

BCP - Bulk Copy Program for Microsoft SQL Server.
Copyright (C) Microsoft Corporation. All Rights Reserved.
Version: 11.0.2270.0

[ACADB]
Driver = ODBC Driver 11 for SQL Server
Server = jdbc:10.30.8.34,1433
Database = ACADB
[ACADB1]
Driver = ODBC Driver 11 for SQL Server
Server = tcp:10.30.8.34,1433
Database=ACADB
[ACADB3]
Driver = ODBC Driver 11 for SQL Server
Server = jdbc:10.30.8.34,1433
Database = ACADB

with the correct password, I can 'login' to my db but the prompt is kind of strange, it should be SQL> instead of number>.
NO trans-SQL command is been accepted there. The only command that worked was EXIT.
Note protocol used is jdbc not tcp. Using tcp as protocol would just give me error, see below.

sqlcmd -S10.30.8.34 -dACADB1 -Uptevw
Password:
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Cannot open database "ACADB1" requested by the login. The login failed..
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user 'ptevw'..


I might be onto something but I can not verify if the drivers are working properly. Since I can not verify if the connection is working right, there is really no point for me to proceed with testing using my program which was written in Peoplecode.

I have a quite weird situation. I'm using sqlcmd to run a script with the command:

SName is the IP\Instance like 10.10.10.100\MyInstance

The content of test.sql is simply:

When I run it gives me the following error:

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Data source name not found and no default driver specified.

***If I copy and paste the script into another machine and run it works fine.

Why is it trying to connect via ODBC?

I believe it's an environment issue but I don't know where to start looking.

1 Answer 1

When using SQLCMD from the command line, it uses the Microsoft ODBC driver by default.

You'll need to configure ODBC in the target environment for SQLCMD to work.

I have a SQL 2014 EXPRESS server. I want to schedule automatic backups using the SQL Server Maintenance Solution by Ola Hallengren. In order to do this I have created a CMD script which is to be used by Task Scheduler. However, I am having some trouble connecting to the SQL server using the command sqlcmd in the command prompt.

For starters I'm just trying to directly connect through the prompt using the command

Where 12.0.2269 is the IP of my server. I have also tried connecting using the name of the server, and I have also tried connecting using specific ports, which have been opened in the firewall (both inbound and outbound), e.g.

In addition, I have ticked off the field that says "Allow remote connections to this server" in the SQL Server Management Studio. The server I am trying to connect to is "located" on the machine I am working on, so I don't quite get what is wrong. I hope you can help. When I connect using the command

This is my configuration. I have a redhat 6.6 x64, I need to use it to connect to a remote Ms SQL 2008 database server via odbc/jdbc. I have another setup with Windows 2008r2 as client connection to the same MS SQL 2008 server so I knew the ip, password, connectivity are setup correctly on the SQL server side.

I had successfully install the driver manager and odbc drivers for Microsoft ODBC Driver 11 For SQL Server for Linux.

the result of command odbcinst -q -d -n "ODBC Driver 11 for SQL Server" is

[ODBC Driver 11 for SQL Server]
Description=Microsoft ODBC Driver 11 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so
Threading=1
UsageCount=1

The result of command /usr/bin/odbcinst -q –j is

unixODBC 2.3.0
DRIVERS. /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES. /etc/ODBCDataSources
USER DATA SOURCES. /root/.odbc.ini
SQLULEN Size. 8
SQLLEN Size. 8
SQLSETPOSIROW Size.: 8

the result of bcp -v

BCP - Bulk Copy Program for Microsoft SQL Server.
Copyright (C) Microsoft Corporation. All Rights Reserved.
Version: 11.0.2270.0

[ACADB]
Driver = ODBC Driver 11 for SQL Server
Server = jdbc:10.30.8.34,1433
Database = ACADB
[ACADB1]
Driver = ODBC Driver 11 for SQL Server
Server = tcp:10.30.8.34,1433
Database=ACADB
[ACADB3]
Driver = ODBC Driver 11 for SQL Server
Server = jdbc:10.30.8.34,1433
Database = ACADB

with the correct password, I can 'login' to my db but the prompt is kind of strange, it should be SQL> instead of number>.
NO trans-SQL command is been accepted there. The only command that worked was EXIT.
Note protocol used is jdbc not tcp. Using tcp as protocol would just give me error, see below.

sqlcmd -S10.30.8.34 -dACADB1 -Uptevw
Password:
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Cannot open database "ACADB1" requested by the login. The login failed..
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user 'ptevw'..


I might be onto something but I can not verify if the drivers are working properly. Since I can not verify if the connection is working right, there is really no point for me to proceed with testing using my program which was written in Peoplecode.

Читайте также: