Insert filetable using fileupload from local - sql-server

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

Related

Bulk insert is not working in MS SQL Server

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

Access to SQL Server FileTable from IIS

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>

Sql Server Database Mail attachments from FileTable msg 22015 (file is invalid)

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

problems with automatic creation of the database in EF4

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.

Create a SQL Server database on a remote machine mdf file path issue

I'm trying to create a MS Sql Server database on a database instance running on a remote machine. When I'm doing so I need to be able to specify the path to the database (.mdf) file. If I try to create a database in a folder which doesn't exist, SQL Server will just fail (wouldn't it be nice if it created the folder structure automatically).
Is there any way that I can create the folder path on the target machine in SQL before I try to create the database, or at least to determine what the default folder is for new databases in which I could safely create the new database file?
If you have appropriate permissions, and xp_cmdshell is enabled, you can:
EXEC xp_cmdshell 'md "<path>"';
--...repeat for each node in the path
If cmdshell is disabled, again assuming appropriate permissions, you can enable it temporarily using sp_configure:
Ancient article removed
Don't forget to set it back!
Otherwise why can't you let the engine place the database files in their default location? If you are using a drive other than C:, you'll also need to verify that the drive you specify even exists, and shouldn't you check with the user that it is okay for you to put these files elsewhere? If you choose some arbitrary location they might not know to check there for active SQL Server files.
You can check the default path by using xp_regread (undocumented, unsupported)... these are in the registry as keys DefaultDataDir and DefaultLogDir for the default instance under:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer
If it's not the default instance, check this article:
http://foxtricks.blogspot.com/2009/06/how-to-determine-default-database-path.html
Are you doing this just so that you can name your MDF/LDF files the way you want to, instead of dbname-data, dbname-log? If so, why? Have you written scripts that depend on the physical name of the file? Really curious as to the motivation behind this.

Resources