bcp "select __$Operation from ##t" queryout "C:\sample.csv" -c -t -C 1252, -T -S myserver
This column is present in sys.fn_cdc_get_min_lsn table.
Error:
Starting copy...
SQLState = S0022, NativeError = 207
Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Invalid column name '__'.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]Unable to resolve column level collations
Related
Getting the following error while running
isql EXDB -v
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
Below are contents of odbc.ini
[EXDB]
Description = eXtremeSQL data source
Driver = eXtremeSQL
#DATABASE = exdb
SERVER = localhost:5099
odbcinst.ini :
[eXtremeSQL]
Description = ODBC for eXtremeSQL
Driver =
Setup =
Driver64 = /root/extremeDB-v8.0.1799.25104.1/odbc/bin.so/libmcoodbc_drv_debug.so
Setup64 =
FileUsage = 1
isql command is giving some error. Please help
So I'm using bcp to import a csv file to my SQL database.
This is the command:
bcp table in D:\temp\some_file.csv -T -S serverName -d dbName -F 2 -c -t "," -r "\n"
I'm getting the following error when I try to import the file:
Starting copy...
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
SQLState = 22001, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]String data, right truncation
24 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 31 Average : (774.19 rows per sec.)
The last 2 columns of the csv file contains User full name ("surname, name"), Customer full name ("surname, name")
SYS Hostname,SYS Domain,User Name,Customer Name
server1,test.com,"surname, name","surname2, name2"
Is it possible to ignore the , between the ""?
Thanks
EDIT:
As #AlwaysLearning said:
You have a Quoted CSV file which is something the bcp.exe process
cannot handle. As per RFC4180 your data row has four fields server1
test.com surname, name and surname2, name2 but bcp.exe only sees the
commas so thinks it is six fields. Consider alternative methods - such
as using a PowerShell script to load the data file into a DataTable
using Import-Csv and then insert the DataTable using an SqlBulkCopy
object over an SQL connection
There is any other option to import a CSV file by command line o SQL script?
Thanks
See this response here. BCP can work so long as the quoted fields are always quoted, on every line of the file. Regardless of whether the name value contains a comma or not. The question below is regarding export, but it works the same on import. You essentially tell BCP that the delimeter is "," and not just ,
SQL Server BCP Export where comma in SQL field
I am trying to Connect to sql server database but I get this error:
File "C:\Python37-32\SqlVersionpr_import.py", line 528, in proceed
with pyodbc.connect('DRIVER={ODBC Driver 17 for SQL
Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) as myDbConn:
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found
and no default driver specified (0) (SQLDriverConnect)')
My code:
server = '***********'
database = '*****'
username = '***********'
password = '***********'
with pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) as myDbConn:
with myDbConn.cursor(as_dict=True) as cursor:
cursor.execute(''' select * from empInfo where ssn = %s and storeid = %s ;''',(strLastSsn,stono))
emp_rows = cursor.fetchall() or []
I have a perl application hosted on heroku which needs to connect with some sql server. I am unable to establish connection. It fails with following error:
DBI connect('Driver={ODBC Driver 11 For SQL Server}; Server=****; UID=****; PWD=****','',...) failed: [unixODBC][Driver Manager]Data source name not found, and no default driver specified (SQL-IM002) at work.pl line 12.
This is the code.
work.pl
use strict;
use warnings;
use DBI;
my $DRIVER = '{ODBC Driver 11 for SQL Server}';
my $SERVER = '****';
my $UID = '****';
my $PWD = '****';
my $x = DBI->connect("dbi:ODBC:Driver=$DRIVER; Server=$SERVER; UID=$UID; PWD=$PWD");
Relevant Environment Vars:
LIBRARY_PATH=/app/.platform/vendor/usr/lib64:
LD_LIBRARY_PATH=/app/.platform/vendor/usr/lib64:
PATH=/app/.platform/vendor/usr/bin:/app/vendor/perl/bin:/usr/bin:/bin
LANG=en_US.UTF-8
ODBCSYSINI=/app/.platform/vendor/etc
HOME=/app
PWD=/app
ODBCINI=/app/.platform/vendor/etc/odbc.ini
ODBCHOME=/app/.platform/vendor/etc/
PERL5OPT=-Mlocal::lib=/app/vendor/perl-deps
odbcinst.ini:
Description = ODBC for PostgreSQL
Driver = /usr/lib/psqlodbc.so
Setup = /usr/lib/libodbcpsqlS.so
Driver64 = /usr/lib64/psqlodbc.so
Setup64 = /usr/lib64/libodbcpsqlS.so
FileUsage = 1
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc5.so
Setup = /usr/lib/libodbcmyS.so
Driver64 = /usr/lib64/libmyodbc5.so
Setup64 = /usr/lib64/libodbcmyS.so
FileUsage = 1
[ODBC Driver 11 for SQL Server]
Description = Microsoft ODBC Driver 11 for SQL Server
Driver = .platform/vendor/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0
Threading = 1
UsageCount = 1
odbc.ini is empty.
Am I missing something?
Tried everything and found the reason. It should be dbd:ODBC:DRIVER instead of dbd:ODBC:Driver.
I am trying to connect SQL server using ODBC.
Could some one help interpreting what this error is and how this can be rectified?
Kindly note that there are no password issues as I use the same credentials to connect to the SQL server using Aqua studio.
dbhandle <- odbcDriverConnect('driver={SQL Server};server=SQLBBAQA;database=bbadb;uid = "aaa_bbb_ccc", pwd = "aaabbbccc123&" ')
Warning messages:
1: In odbcDriverConnect("driver={SQL Server};server=SQLBBAQA;database=bbadb;uid = \"aaa_bbb_ccc\", pwd = \"aaabbbccc123&\" ") :
[RODBC] ERROR: state 08001, code 17, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
2: In odbcDriverConnect("driver={SQL Server};server=SQLBBAQA;database=bbadb;uid = \"aaa_bbb_ccc\", pwd = \"aaabbbccc123&\" ") :
[RODBC] ERROR: state 01000, code 2, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
3: In odbcDriverConnect("driver={SQL Server};server=SQLBBAQA;database=bbadb;uid = \"aaa_bbb_ccc\", pwd = \"aaabbbccc123&\" ") :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute
4: In odbcDriverConnect("driver={SQL Server};server=SQLBBAQA;database=bbadb;uid = \"aaa_bbb_ccc\", pwd = \"aaabbbccc123&\" ") :
ODBC connection failed
I see multiple mistakes in the connection string:
server=SQLRAPQA should be in the form server=MACHINE\INSTANCE. Use server=.\SQLRAPQA if the instance is located on the same machine.
Remove all whitespaces.
Use ; as separator, not ,.
As referenced by zx8754, in RODBC odbcDriverConnect() Connection Error it is shown that a connection string should look like:
'driver={SQL Server};server=servername\\instancename,port;database=testing;uid=abc;pwd=123456' . Note the double occurences of \, this seems to be rodbc specific.