We have a post-deployment script in our SQL Server
project which essentially performs a bulk-insert
to populate tables after they're created. This is done by reading several .csv
files:
BULK INSERT
[dbo].[Table1]
FROM '.\SubFolder\TestData\Data1.csv'
WITH
(
ROWTERMINATOR = '0x0a',
FIELDTERMINATOR = ','
)
BULK INSERT
[dbo].[Table2]
FROM '.\SubFolder\TestData\Data2.csv'
WITH
(
ROWTERMINATOR = '0x0a',
FIELDTERMINATOR = ','
)
The problem is Visual Studio is having a hard time finding the files:
Cannot bulk load because the file ".\SubFolder\TestData\Data1.csv" could not be opened.
Operating system error code 3(The system cannot find the path specified.).
The .csv files are checked in to the source control and I do see them when I go to the folder they're mapped to on my machine. I assume the problem is .
isn't returning current path for the sql file being executed. Is there a way to get the relative path? Is there a macro (or a SQLCMD Variable
maybe) that would give me current path of the file?