SQL Stored Procedure Send mail with attachement - sql

i have a stored procedure that sends an email with an attachment, one of the developers decided to drop the lookup table with the file paths in, I've recreated the table but cant remember how the string needs to be for the file path and name to be picked up.
I've tried N'C:\Filename.xls' AND N'\\PCName\temp\filename.xls' and a few other variations but keep getting "Attachment file N'C:\Filename.xls' is invalid".
I've assigned the relevant file permissions so that there are no access restrictions on the folder or file that the file is stored in.
Thanks

I've figured it out! The SQL instance is set up to use the built in SA account for authentication by default which has no access to local drives!! what a pain!!

Related

how to read a tab delimited .txt file and insert into oracle table

I want to read a tab delimited file using PLSQL and insert the file data into a table.
Everyday new file will be generated.
I am not sure if external table will help here because filename will be changed based on date.
Filename: SPRReadResponse_YYYYMMDD.txt
Below is the sample file data.
Option that works on your own PC is to use SQL*Loader. As file name changes every day, you'd use your operating system's batch script (on MS Windows, these are .BAT files) to pass a different name while calling sqlldr (and the control file).
External table requires you to have access to the database server and have (at least) read privilege on its directory which contains those .TXT files. Unless you're a DBA, you'll have to talk to them to provide environment. As of changing file name, you could use alter table ... location which is rather inconvenient.
If you want to have control over it, use UTL_FILE; yes, you still need to have access to that directory on the database server, but - writing a PL/SQL script, you can modify whatever you want, including file name.
Or, a simpler option, first rename input file to SPRReadResponse.txt, then load it and save yourself of all that trouble.

Import text file into a table in db2

Text file contains data like
1,'name',34
2,'name1',23
If you have Access Client Solutions, you can use the File Transfer function to upload the file.
Also can upload directly from Excel if the file is open:
https://www.ibm.com/support/pages/transferring-data-excel-using-access-client-solutions
When the Db2-server runs on Linux/Unix/Windows, you can CALL a stored procedure to do import or load.
BUT, the file to be imported or loaded must already be on the Db2-server, or on a file-system that the Db2-server process can read. So any filenames are relative to the Db2-server (not to your workstation, unless of course the Db2-server runs on your workstation).
If the target table already exists, the connected-userid needs suitable permissions on that table. If the target table does not exist, you need to create it first.
Also the userid needs execute permission on the stored procedure that does the work.
So there are three steps:
copy the file to be imported (or loaded) to a location that the Db2-server can read.
call the ADMIN_CMD stored procedure with parameters telling it what to do, in this case to import a file.
Examine the result-set of the stored procedure to see what happened. If the import or load failed, you need to run the SQL listed in the MSG_RETRIEVAL column of the result-set to see why it failed (assuming you used MESSAGES ON SERVER option to import).
See the Db2 documentation online here for import or load
There are also many examples here on stackoverflow.
So do your research and learn.
On Db2 11.5 you can use a REMOTE TABLE to import a text file into Db2
Use the REMOTESOURCE YES option if the file is on your client and not on a directory visible to the database server
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r_create_ext_table.html?pos=2

Dynamically populate external tables location

I'm trying to use oracle external tables to load flat files into a database but I'm having a bit of an issue with the location clause. The files we receive are appended with several pieces of information including the date so I was hoping to use wildcards in the location clause but it doesn't look like I'm able to.
I think I'm right in assuming I'm unable to use wildcards, does anyone have a suggestion on how I can accomplish this without writing large amounts of code per external table?
Current thoughts:
The only way I can think of doing it at the moment is to have a shell watcher script and parameter table. User can specify: input directory, file mask, external table etc. Then when a file is found in the directory, the shell script generates a list of files found with the file mask. For each file found issue a alter table command to change the location on the given external table to that file and launch the rest of the pl/sql associated with that file. This can be repeated for each file found with the file mask. I guess the benefit to this is I could also add the date to the end of the log and bad files after each run.
I'll post the solution I went with in the end which appears to be the only way.
I have a file watcher than looks for files in a given input dir with a certain file mask. The lookup table also includes the name of the external table. I then simply issue an alter table on the external table with the list of new file names.
For me this wasn't much of an issue as I'm already using shell for most of the file watching and file manipulation. Hopefully this saves someone searching for ages for a solution.

Operation must use an updateable query ASP Query Failing

Below is the error code I am receiving after running an Update query
2015-02-18 17:30:12 192.168.2.240 GET /webinsert.asp Date=02/10/2015&Field=38|443|80004005|Operation_must_use_an_updateable_query. 80 - Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 500 0 0 56
I recently moved the database from one server to another. I can read the data no problem. It has proper IIS User rights (read and write). Any help would be greatly appreciated.
Make sure your IIS user has write permissions to the .mdb file and the folder containing the .mdb file (/wwwroot/db in your case based on your comment). The folder requires write permission because Access creates an .ldb file in the same folder to handle database locking.
Also from here:
You may also need to give read/write permission on the "Temp" folder
because Jet may create temporary files in this directory.
I assume they are referring to C:\Windows\Temp but I'm not positive.

directory name too long pl/sql

I tried to create a file using Oracle UTL_FILE.FOPEN command but i get this error.
Is there an alternative?
log_file:=UTL_FILE.FOPEN("P:\Documentation\Project Team\SA\CSR_Documentation\SHR-10500",'outputforDeleteStudentGroup.txt', 'W');
I dont want to say create or replace directory because the directory already exists.
Please suggest.
Thanks,
Sriram
CREATE OR REPLACE DIRECTORY does not create a directory at the operating system level. It creates an Oracle directory object. You want to create an Oracle directory object that points to a directory at the operating system level. You could potentially go with the very old-school approach of modifying the UTL_FILE_DIR initialization parameter to include P:\Documentation\Project Team\SA\CSR_Documentation\SHR-10500 and reboot the database but that is not something that I would recommend.
The first parameter to UTL_FILE.FOPEN should be a string which means that it should be enclosed in single quotes not double quotes.
Is the P:\ drive something that exists on the database server's file system? Or is it a network drive that gets mounted by the database server? Or is it a directory that is available to the client?