I'm transitioning email services in an web (mvc3) application from .Net to sql Database Mail. Some of the content we want to send as attachments has been uploaded to a sql FileTable. When I use the UNC path for the attachment (#file_attachments=), I get this error:
Msg 22051, Level 16, State 1, Line 0 Attachment file
\\computername\mssqlserver\foldername\foldername\DE107D2C-B945-4F1E-A4B9-4B398C9DE758.jpg)
is invalid.
I can open the file directly using the same path, and when I copy the file to a local folder, the file attaches fine. I suspect that the issue is folder permission for the FileTable directory. But I can't find any hooks to set the rights for that folder.
I'm running the EXECUTE msdb.dbo.sp_send_dbmail locally in SSMS (local sql instance) using windows authentication.
Any suggestions would be much appreciated.
This behavior was validated in the Microsoft Database Engine forum and I submitted feedback: https://connect.microsoft.com/SQLServer/feedback/details/756716/sql-server-database-mail-attachments-from-filetable-msg-22051-file-is-invalid
Note that the error code I had in this title should be 22051 and not 22015.
In the mean time, I'm using a work around of copying the files using the sql command shell to another local folder, and using that path for the attachment
Thanks.
share your attachement folder to Network service user in which attchment file exist.
and give attachemnt file path like \\ip_addres\filefolder\abc.pdf to send_dbmail stored procedure.
This will work if file and sql server are on different machines
Related
Bulk insert is not working when I try to read in the .CSV file data from the network path, it throws an error message saying
Cannot bulk load because the file couldn't be opened Operating system error code 5 (Access is denied)
If I try to bulk insert the same file data from the local drive of the server where SQL Server is running, it works fine without any issue. I checked the access rights with the network path, I do have full access. I need help to resolve this issue.
The data file name must specify a valid path from the server on which SQL Server is running.
If the data file is a remote file, specify the Universal Naming Convention (UNC) name.
A UNC name has the form :
\\Systemname\ShareName\Path\FileName.
For example,
\\SystemX\DiskZ\Sales\update.txt.
For more details: https://learn.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-2017
After creating filetable I've got a shared folder
\\<my domain>\mssqlserver\<filestream directory>\<my table>
I've made all nesessary settings in SqlServer Configuration manager to make it available and added couple of files with database stored proc.
I made virtual folder for my web site
http://localhost/<my ewb site>/<virtual folder>/
referencing shared table folder.
When I try to get file from folder I get en error:
HTTP 500.19 - Internal Server Error
Code 0x80070032
I found something in answer of this question
Access Denied when inserting file into Sql Server 2012 FileTable using File.CreateFile in ASP.NET website
But it's only a database part of configuring.
I don't understand how to configure IIS and virtual folder to grant access to shared folder.
Not sure if this is relevant to your situation, but I came across the same problem. 2 out of 3 sites that I setup worked fine with the UNC path virtual directory pointing to the SQL filetable share, but the 3rd site got the error above. The reason was because this site was had both IIS and SQL on the same server, and using the server name in the UNC path was causing a reparse and checking for directory change notifications, which mentioned in the comments above aren't supported by SQL. So I changed the UNC path to use localhost instead of the server name and it worked! So, instead of:
\\<my domain>\mssqlserver\<filestream directory>\<my table>
use:
\\localhost\mssqlserver\<filestream directory>\<my table>
I have some basic question about filetable.
How do I upload file from local to server(directly to filetable directory)?
I have tried, but error 'access denied to xxx path' was popped up
When I try to insert filetable using sql command (BULK insert 'filestream'), it did say the path was not found.
What I have tried so far:
I have granted user from appPool permission to access filetable db
(grant access filetable)
I have enable filestream remote access client in sql server config
I have set non-transactional setting in options tab in filetable db properties to 'full'
the error message when I'm using fileupload to move file from local to filetable directory on server
Access to the path '\\BHPREPOSRV\testSLA\LET THE MUSIC HEAL Y.mp3.jpg' is denied.
Please help me.
Thanks in advance.
It looks like you are missing a couple of the components of the file table UNC path. In addition to the server name, the path must include the instance FILESTREAM share name, database FILESTREAM directory, and file table name.
\\server-name\instance-filestream-share\database-filestream-directory\file-table-name\LET THE MUSIC HEAL Y.mp3.jpg
I'm attempting to get SQL Server Service Broker working across database instances and an at the stage of copying certificates (from initiator to target and vice versa). I can back up the certificate to a file but once created I can't open the file or copy it to any other location. If I try and open the file I get a message box with the title "Invalid Public Key Security Object File" and the message "Access is denied.".
The server is within the local domain and is running Windows Server 2008 R2 Enterprise with SP1.
This works (but I cannot do anything with the file):
BACKUP CERTIFICATE UserCertificateB TO FILE='C:\Certs\UserCertificateB.cer';
This doesn't work:
BACKUP CERTIFICATE UserCertificateB TO FILE='\\localmachine\Certs\UserCertificateB.cer';
Error message is:
Msg 15240, Level 16, State 1, Line 2
Cannot write into file '\localmachine\Certs\UserCertificateB.cer'. Verify that you have write permissions, that the file path is valid, and that the file does not already exist.
I can back up the certificate to a file but once created I can't open the file or copy it to any other location.
Yes, the access is restricted to the SQL Server service account. Grant permissions as appropriate on the file, using an administrative account. Use icacls.
Cannot write into file '\localmachine\Certs...'
You are doing a 'double hop' so it requires Kerberos constrained delegation. Contact your network administrator to set it up properly for you.
I know this is an old question, but maybe this answer will be relevant to others that may find the same issue.
If it shows the error ‘Msg 15240, Level 16, State 1, Line 8
Cannot write into file 'C:\tmp\cert\MY_TDE_CERT_KEY.PVK'.
Verify that you have write permissions, that the file path is valid, and that the file does not already exist.’
It is because the script has to be executed on the server and not the local computer connected to the server.
Once the SQL script executed in the server then the files will appear in the selected folder in the server (must create a local directory).
Error (the image shows the path of the local computer, it was the wrong path, must be in the server):
After executing in server
Learned this from Microsoft:
"The path is relative to the SQL Server instance. The path needs to be setup on the machine hosting the instance."
I'm learning ASP.NET MVC 3 with Entity Framework Code First. I'm following a tutorial and I downloaded the corresponding solution for testing on my local machine. Now, something I didn't understand very well is about the automatic creation of the database (if this one didn't exist yet on disk). The very first time I run the application, the database is created for me. That's ok.
Here is the section in Web.config
<add name="BlogContext"
connectionString="Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC.mdf;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
But I have two problems:
1st. For testing purpose, I deleted the database on disk and run again the solution. I thought that the database would be automatically created but I was wrong: I got the error message below:
{"Unable to open the physical file \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf.mdf\". Operating system error 2: \"2(failed to retrieve text for this error. Reason: 15105)\".\r\nCannot open database \"CodeFirstMVC.mdf\" requested by the login. The login failed.\r\nLogin failed for user 'sa'.\r\nFile activation failure. The physical file name \"c:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQL2008\\MSSQL\\DATA\\CodeFirstMVC.mdf_log.LDF\" may be incorrect."}
I noticed that if I changed the file name in my Web.config then the database is again successfully created. Can you explain me? Why do I have to change the database name to get it running again?
2nd. The database is created in the folder located in C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\DATA. I would like to store my database in the App_Data directory. How can I proceed?
Initial catalog is not path to file. It is the name of database. AttachDbFilename is used to specify the file so your connection string should look like:
Data Source=.\SQL2008;Initial Catalog=CodeFirstMVC;AttachDbFilename=|DataDirectory|CodeFirstMVC.mdf;Integrated Security=SSPI
Where |DataDirectory| instructs SQL server to use local application data directory instead of global SQL Server data directory. Local data directory for web application is App_Data.
Edit:
I just noticed that you are probably using full SQL server instead of SQL server express. As I know creating database in App_Data automatically is feature of SQL server express. That also explains first error because SQL server created database called CodeFirstMVC.mdf and stored the database in its global data directory within CodeFirstMVC.mdf.mdf file and transaction log in CodeFirstMVC.mdf.ldf file. It also registered that database internally. By deleting files you didn't remove database from SQL server. You just break its functionality but SQL server still believes that the database exists. That is also reason why you have to change the name to make it work.