Trouble With Bulk Insert - sql-server

I am trying to bulk insert some data from a txt file and I am having a lot of trouble. Whenever I try to do this I get the following error. Cannot bulk load because the file "H:\NAPApplication.txt" could not be opened. Operating system error code 3(The system cannot find the path specified.).
Here is the code I used for the bulk insert.
BULK
INSERT NAPApplication
FROM 'H:\NAPApplication.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
);
I used Test-Path in Powershell to double check that the file exists where I say it does. I am confused why the path specified cannot be found if it is obviously there.
EDIT: SQL Server is on a different machine than the box that the file I am looking for is on. Is there anyway to tell the computer to look into my computer instead of the server?

The file needs to be in a location that the SQL Server can see. It cannot see your H: drive unless it is shared. Yoiu would then probably have to reference it by its UNC path. Can you not use a network share?

Related

Does DatabaseIntegrityCheck.sql log to text files in disk?

I want to setup checkdb using DatabaseIntegrityCheck.sql from Ola-hallengren. I have passed LogToTable = 'Y'. But will it log to disk as well in text files? I did not find any parameter for that.
P.S. I know that jobs from MaintenanceSolution.sql do log to files in disk.
Script reference : DatabaseIntegrityCheck.sql
The procedure do not, byt itself log to disk. There isn't really any clean way to write to disk from inside T-SQL. Hence using an output file in the job step (like what the create job section of MaintenanceSolution does).

Inputting a .sas7bdat file on SAS On Demand

I am using SAS Studio (the browser version) instead of a desktop SAS program.
I am trying to read a .sas7bdat file that I have uploaded onto a folder on SAS Studio.
libname HW5 '~/home/xxxxxxxxxxxx/sasuser.v94/HW5';
DATA FILE1;
set HW5.orders;
RUN;
I get the error:
ERROR: File HW5.ORDERS.DATA does not exist.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FILE1 may be incomplete. When this step was stopped there
were 0 observations and 0 variables.
WARNING: Data set WORK.DISCOUNT_RET was not replaced because this step was stopped.
Here is the image of the folder:
https://ibb.co/hN83ua
I realize this is a simple error but I don't know how to fix it. Thanks! If nothing works, can i read this via infile?
Right click on the HW5 folder in the list on the left and select properties. This should show you the physical location for that folder. Copy it and paste it into your LIBNAME statement enclosed in quotes. Most likely the issue was your inclusion of the ~ in front of the path.
libname HW5 '/home/xxxxxxxxxxxx/sasuser.v94/HW5';

Check if a file exists in UNIX from SQLplus without UTL_FILE

My current scenario is like this:
I need to login to sqlplus from a shell script to call a stored procedure.
After that I need to create a CSV file by SPOOLING data from a table.
Then I need to check whether the CSV file has been created in a particular directory and depending on the result an update query needs to be run.
I know that this can be checked within sqlplus with the help of UTL_FILE package but unfortunately due to Client policies,the access of this package is restricted in the current system.
Another way is to exit from sqlplus and perform the file check in UNIX and then again log in to sqlplus to perform the rest actions. But this I believe would result in slower execution time and performance is an important factor in this implementation as the tables contain huge volumes of data(in millions).
So is there any other way to check this from sqlplus without exiting from the current session?
System Info:
OS - Red Hat Enterprise Linux
Database - Oracle 11g
If the file is on the same machine that you're running SQL*Plus on, you could potentially use the host command.
If the file you're checking is the same one you're spooling to, it must exist anyway, or you would have got an SP error of some kind; but if you do want to check the same file for some reason, and assuming you have a substitution variable with the file name:
define csv_file=/path/to/spool.csv
-- call procedure
spool &csv_file
-- do query
spool off
host ls &csv_file
update your_table
set foo=bar
where &_rc = 0;
If the file exists when the host command is run, the _rc substitution variable will be set to zero. If the file doesn't exist or isn't readable for any reason it will be something else - e.g. 2 if the file just doesn't exist. Adding the check &_rc = 0 to your update will mean no rows are updated if there was an error. (You can of course still have whatever other conditions you need for the update).
You could suppress the display of the file name by adding 1>/dev/null to the host command string; and could also suppress any error messages by also adding 2>/dev/null, though you might want to see those.
The documentation warns against using &_rc as it isn't portable; but it works on RHEL so as long as you don't need your script to be portable to other operating systems this may be good enough for you. What you can't do, though, is do anything with the contents of the file, or interpret anything about it. All you have available is the return code from the command you run. If you need anything more sophisticated you could call a script that generates specific return codes, but that's getting a bit messy.

create flat file in ssis package

I'm working on creating a csv export from a SQL Server database and I've been familiar with a process for doing so that admittedly, I've never completely understood. The process involves creating a "template" file, which defines the columns and structure for the file export. Once the "template" file exists, you can use a Data Flow task to fill it and a File System Task to copy it to the final storage destination with whatever file name you'd like (frequently a date/time stamp).
Is there a reason that you can't simply create a file directly, without the intermediate "template" file? I've looked around for a bit and it seems like all the proposed solutions involve connecting to an existing file. I see that there is a "Create File" Usage type for a "File" connection manager, but you can't use it in any File System Task. The only File System Type connection managers you can use relative to a file are "Copy", "Delete", "Move", "Rename", and "Set Attributes".
Is there a way to create a file at package run time and fill it?
The whole point of SSIS is to create a data flow with metadata so that the data can be manipulated - if you just want to go database direct to CSV you are probably better off using bcp (bulk copy program) from the command line. If you want to include it as part of a SSIS package just add an Execute Process Task and add the command line to that. You can dynamically change the included columns or the output file by adding an expression to the task. You could also call bcp though TSQL using an Excute SQL Task.
One other option is to concatenate all your columns in your query inter-spaced with a comma literal and output to a text file with just one very wide column.
For documentation on bcp look here

Why doesn't my SSIS File System Task recognize my destination path?

I've set up a File System path inside a ForEachFile enumerator in SSIS 2012. I'm iterating over a directory, loading each file, archiving that file, then processing the next file, etc. I've set the Destination folder via an expression that uses a Project Param value, and I get the source file from the variable set in the ForEachFile enumerator. The File System task says it can't find my Destination folder:
Here's the File System Task:
And proof that the destination folder exists:
Why am I getting this error? I'd swear I've used the exact same technique in SSIS 2008 and 2005. This is 2012, but it should work the same way.
I met the same problem and to resolve it i create a variable and i put something like this in the path.Be carefull you must put double "\ \".
So the path must be like this:"\ \ \ \ad1hfdalhp001\ \d$\ \data\ \Archive\ \"
The DestinationConnection field must contain a reference to a flat file connection. The error is saying that you have no Flat file connection manager with that name.
DestinationConnection should not be a free text field. You should be able to open a drop down in the DestinationConnection field and select or create a connection manager.
You will need to configure your output file path as the ConnectionString property on the file connection manager referenced in the DestinationConnection field.
Using a UNC is still an option. Similar to as you've done with the Source, on your Destination, set IsDestinationPathVariable = True and then push \server\path into a Variable User::ArchivePath or similar.
Otherwise, it is as user3922917 indicates: if IsDestinationPathVariable is false, then you need to use a File Connection manager.
In your comments, you indicate that you're building the UNC path based on an Expression in the File System Task. I find I have a better experience when I build my expressions in SSIS Variables and then simply assign that Variable into the Task's Expression. While this step may seem to provide another layer of maintenance, put a break point on the Task and tell me what the expression evaluates to. And you can't. It's only available to the object to use and you are unable to inspect it so you're left high and dry if your formula is off. Which never happens when you're having to deal with escaping a UNC path

Resources