I have a simple SQLCMD
script that includes some lines like this:
/* Load data into Exampletable */
BULK INSERT dbo.Example
/* NOTE: I've tried single AND double quotes here. */
FROM "C:\Example Filepath\test.csv"
WITH
(
/* skip the first row containing column names */
FIRSTROW = 2,
/* specify how fields are separated */
FIELDTERMINATOR = '|',
/* specify how lines end */
ROWTERMINATOR = '\n'
)
When I run it on the command line, I get an error like this:
Sqlcmd: 'C:\Example': Invalid filename.
I think that having a space in the path is causing the path to be cut off, but I can't figure out a syntax that works. Does anybody have any experience with this?
Connect to a SQL Server instance using Windows Authentication. Open the Command Prompt and switch to the location of the sqlcmd utility. Then, execute the following command by replacing the connection parameters with the server ( server_name ) and instance ( instance_name ) names to which you want to connect.
The setvar command is used to define scripting variables. Variables that are defined by using the setvar command are stored internally. Scripting variables should not be confused with environment variables that are defined at the command prompt by using SET.
You could try to execute sqlcmd.exe -? in a process in your C# app - if it works, then SQLCMD is present - if not, it'll tell you something like "file not found" or "command invalid" or something ....
SQLCMD is installed with SSMS and with the database engine. This means it's going to be installed on the server where your instance is located and probably your workstation as well.
The error message sounds like sqlcmd cannot find the .sql file.
Try sqlcmd "c:\example filepath\test.sql"
from the command prompt.
Strings are quoted with single quotes in TSQL, with double quotes in cmd.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With