SQL SERVER 2008 - Sqlcmd: Error: Internal error at ReadText (Reason: No mapping for the Unicode character exists in the target multi-byte code page) - sql

I'm using MS SQL SERVER 2008 R2 and try to use sqlcmd from command prompt. But getting this error when I try to run sqlcmd with -i command, which is for input file.
This command which is executing simple test.sql(containing only SELECT ##SERVERNAME for test purposes) gives an error:
sqlcmd -S serverName -i test.sql
BUT, this command works well (I just specify command by -q query, instead of reading from file):
sqlcmd -S serverName -q "SELECT ##SERVERNAME"
the error message is:
Sqlcmd: Error: Internal error at ReadText (Reason: No mapping for the Unicode character exists in the target multi-byte code page).
Some issues on google say that this was a known bug and was fixed in SP1, I have installed it but still getting the same problem.

Changing Computer/VM locale and region to US solved the problem.

Related

Errors ("invalid command") when opening a .sql file

I am trying to open a random .sql file off the internet using the following command:
psql -h localhost -d database_name -U postgres < file_name.sql
But when I run this command I just get errors like the following:
invalid command 's
invalid command 's
invalid command 'll
invalid command 'Moving
invalid command 's
invalid command "frequently
It just continuously prints out these invalid command error messages. I thought it might be an encoding problem but I confirmed the file is UTF-8 encoded.
Any suggestions on how I can open this file
To expand and clarify on a_horse_with_no_name's comment - the psql command you are running should be run directly in your shell, not inside pgadmin4.
youruser#yourmachine:~$ psql -h localhost -d database_name -U postgres < file_name.sql
That command should load the contents of file_name.sql in to database_name. Once it's complete, you can use pgadmin4 as normal to interact with the database.
One possibility is that the file contains tabulator keys, which are expanded if you read redirect standard input to the SQL script.
Try using the -f option:
psql -h localhost -d database_name -U postgres -f file_name.sql
Apparently the .sql file was generated through a MySQL dump. I thought it would not matter whether I used PostgreSQL or MySQL but it did. Once I installed MySQL my problem got resolved and I now have a Database ready :)

Error while trying to import .sql file in SSMS

I'm trying to import an sql file of size 3.2GB. So definitely I would need to do it using cmdsql.
But the problem is that the server I'm trying to connect with in SSMS has no password and that is giving me the error.
I'm usig the following command in cmd:
sqlcmd -S DESKTOP-7QKBPG7\SQLEXPRESS -d XVMS-4.6 -U CSNA\kamran.bajwa -P -i C:\Users\kamran.bajwa\Downloads\XVMS\SCHEMA-DATA-16-06-2022\SCHEMA-DATA.sql -o C:\Users\kamran.bajwa\Downloads\XVMS\SCHEMA-DATA-16-06-2022\logs.txt
As of the"-P" there is no password so if I use an empty string "" then it gives me the following error in the log file:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'CSNA\kamran.bajwa'..

Running multiple SQL files in Microsoft SQL Server

I have some SQL files which I can run in a single script in oracle like this:
start create_tst_prod_class_tbl.sql
start create_tst_tran_ins_type_tbl.sql
start create_tst_order_type_tbl.sql
start create_tst_timezone_tbl.sql
Now I want to do that in MSSQL too but I could not figure out how. I have tried following things:
Writing a query like this:
:r "C:\Users\Ferid\Desktop\standard\create_tst_prod_class_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_tran_ins_type_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_order_type_tbl.sql"
:r "C:\Users\Ferid\Desktop\standard\create_tst_timezone_tbl.sql"
and activate SQLCMD mode but when I execute it this error occurs:
A fatal scripting error occurred.
Incorrect syntax was encountered while parsing EXIT.
Creating a batch file in the folder where the SQL files are with this content:
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -U<Username> -P<Password> -E
for %%d in (*.sql) do %SQLCMD% -i%%d
When I run it following error occurs:
Sqlcmd: The -E and the -U/-P options are mutually exclusive.
Creating a batch file in the folder where the SQL files are with this content:
for %%G in (*.sql) do sqlcmd /S <servername> /d <databasename>
-U <username> -P <password> -i"%%G"
pause
When I run it following error occurs:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Named Pipes Provider:
Could not open a connection to SQL Server [53]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related
or instance-specific error has occurred while establishing a connection to SQL Server.
Server is not found or not accessible. Check if instance name is correct and if
SQL Server is configured to allow remote connections.
For more information see SQL Server Books Online..
Sadly I have no access to remote connections options.
Are there any other options or ways to fix these errors?
Your case 2. is working:
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -E
for %%d in (*.sql) do %SQLCMD% -i%%d
OR
SET SQLCMD=sqlcmd -S<Servername> -d<databasename> -U<Username> -P<Password>
for %%d in (*.sql) do %SQLCMD% -i%%d

ORA-12545: Connect failed because target host or object does not exist while connecting through the shell

I am trying to run the sql scripts from shell. My scripts are working fine. It is getting connected to database and applying the sql files. Only thing I am not able to understand is why the below error message is getting logged every time.
Error Message :
ERROR:
ORA-12545: Connect failed because target host or object does not exist
Shell Script:
/opt/ORACLE/app/oracle/product/11.2.0/client_1/bin/sqlplus -s <<eoj >>$LOG_FIL 2>&1
${DBUSER1}/${DBPASS}#${hostBillingDBSID}
#${SQLParm} $RPT_FIL
eoj
try the below.
Shell Script:
#let's include oracle installation in the PATH variable
export PATH=$PATH:/opt/ORACLE/app/oracle/product/11.2.0/client_1/bin
#now just use sqlplus, instead of full path reference.
sqlplus -s ${DBUSER1}/${DBPASS}#${hostBillingDBSID} <<eoj >>$LOG_FIL 2>&1
#${SQLParm} $RPT_FIL
eoj
The user/password(connection string) has to be passed as command line arguments to sqlplus.

Windows 7 OSQL Batch

I have just got a new work PC from running Windows 7. I have installed SQL Server 2008 and I have a batch file that runs an OSQL command as follow:
osql -S MyServer -E -d MSDB -n -o results.txt -i MyScript.sql
For some reason it is giving me exception below:
Specified driver could not be loaded due to system error 126: The specified module could not be found. (SQL Server Native Client 10.0, C:\Windows\system32\sqlncli10.dll).
I am not sure what the issue is and I have even tried to run the batch file using 'Run as administrator'.
OSQL is being deprecated; I would consider converting your code to use sqlcmd or PowerShell. However if you're missing SQL native client you might consider adding it. You can download the sqlncli.msi file for your platform from this URL (more than halfway down the page).