Error while trying to import .sql file in SSMS - sql

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'..

Related

How to connect to an Azure SQL Server using command prompt?

I have an Azure SQL database that I am able to connect using local SSMS.
Server Name - <Server>.database.windows.net
UserName - zrana
Password - *****
The authentication mode I use is here is Active Directory - Password. Is it possible to connect to the database using the sqlcmd utility on the command line?
I am unable to connect using the following command
sqlcmd -S 910005-sql.database.windows.net -d 900046 -U zrana -P ****
There is another database that I created on Azure and tried to connect through Local SSMS.
This time the authentication method is "SQL Server password". I am able to connect to it using local SSMS and through sqlcmd using the same format mentioned above.
Is it possible to connect to an Azure SQL database using AAD? I tried using -G -I options in my command and didn't work.
This is the error I see:
(Adding an answer that is essentially the process we worked through in the comments)
Install the latest sqlcmd from https://learn.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15
run sqlcmd -? to see what version of sqlcmd is actually running - if it isn't the latest version you just downloaded, check your PATH variable etc. You can use the dos command where sqlcmd to find where the command line is searching for sqlcmd
run sqlcmd with the -G switch to specify AAD cred checking, and include your user name an dpassword with the -U and -P options. Be careful with the case of these as -u and -p are different switches entirely.
sqlcmd -S 910005-sql.database.windows.net -d 900046 -G -U zrana -P ****
When you want to use an Azure Active Directory user name and password, you need to provide the -G option and also use the user name and password by providing the -U and -P options. On the -U option please see on my example you need to provide the username#domain,
When using the -G option to connect to SQL Database or SQL Data Warehouse and authenticate using Azure Active Directory, a timeout value of at least 30 seconds is recommended. Use "-l 30". Read more about it on this documentation.
Please see the following example:
sqlcmd -S Target_DB_or_DW.testsrv.database.windows.net -G -U bob#contoso.com -P MyAADPassword -l 30

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

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.

BCP unable to open host data file when migrating to Azure

I haver a sample GTFS data file I am attempting to load to Azure. The command I am using is:
bcp %fullTablePath% in %data_dir% -f %format_file% -S %server% -U %username% -P %password% -k -F %first_row%
where the parameters are replaced accordingly.
When I execute the command, I get:
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 11.0]Unable to open BCP host data-file
This is not a file naming issue because the file is indeed there. If I deliberately spell the file incorrectly, I get the same error. Sounds like a permission issue but who do I grant what permission?
If you see this error in batch file but not from PowerShell check that your
%fullTablePath% or %data_dir% variables are full qualify path/absolute path and not relative path as PowerShell and Batch may have different default path settings which may give you the error of:
Unable to open BCP host data-file

How to execute generated script(.sql file) with schema and data in SQL Server 2008

Using SSMS 2008 I am able to generate a script for a database with huge amounts of data in file ABC.sql on my desktop.
The database has approx. 9 GB of data so I'm unable to open the file. Is there any way to execute the script?
When I try to open it in SSMS I get an error:
The operation could not be completed. not enough storage is available to complete this operation
The template specified cannot be found. Please check that the full path is correct
SQL Server offers 2 command prompt features that can se used for executing large queries - osql (will be removed in future), and sqlcmd
osql is located in the Tools\Binn subfolder. To execute a SQL script:
Start the Command Prompt
Navigate to the folder where the osql utility is located
Run the command in the following format:
osql –H <workstation name> -S <server_name[\instance_name]> -U <user login ID> -P <login password> –i <full path to script>
To execute the large.sql file located in the D:\test, against the Central database on the SQL Server instance Dell\SQL2012, as an sa with the 'sqladmin' password, run the following command:
osql -H Dell -S Dell\SQL2012 -i D:\test\large.sql -U sa -P sqladmin
The sqlcmd command line utility is also located in the SQL Server’s Tools\Binn sub-directory. To execute a SQL script:
Start the Command Prompt
Navigate to the folder where the sqlcmd utility is located
Run a command in the following format:
sqlcmd –S <server name> -d <database name> -i <full path to script> -U <user login ID> –P <login password>
To execute the same as above, run the following command:
sqlcmd -S Dell\SQL2012 -d Central -i D:\test\large.sql -U sa –P sqladmin
Start the sqlcmd Utility
Run Transact-SQL Script Files Using sqlcmd
I use sqlcmd to execute large SQL files.
You can generate script of your database by RightClick on your database Tasks>GenerateScripts> click next on Generate and Script window Check on select specific table choose tables you want Press next Click on Advance option on end of General Category select Type of data to script now choose which kind you want your database to.
Scheme Only: Means this script will create your database.
DataOnly:If you have created database and table this will insert data into it.
Press ok then Next.
Your file is by default save in
C:\Users[UserName]\Documents\ .

How do I open an sql database that I downloaded using the terminal?

How can I import a database with MySQL from terminal?
the syntax from this thread
mysql -u username -ppassword databasename < filename.sql
my input for the file (lahman591) i placed on my root for simplicity sake
mysql> mysql -u root -p lahman591 <c:\lahman591.sql
i get an Error:
ERROR 1064 (42000) You have an error in your sql syntax.
You need to do it from your normal shell (the command is calling the mysql bin), not mysql shell.