简体   繁体   English

使用C#在客户端计算机和服务器计算机数据库之间进行文件传输

[英]file transfer between a client machine and a server machine database using C#

I have this SQL database on a server machine in a network and I want any of the client machines to be able to upload and download files to and from the database accordingly where the files will be saved to the server machine file system and their meta data will be stored in the database. 我在网络中的服务器计算机上拥有此SQL数据库,并且我希望任何客户端计算机都能够相应地向数据库上载文件或从数据库中下载文件,在这些文件中文件将保存到服务器计算机文件系统及其元数据中将存储在数据库中。
What is the best method to perform that task? 执行该任务的最佳方法是什么? and how shall I implement it using C# winform application? 以及如何使用C#winform应用程序实现它? thx in advance @_@ 提前谢谢@ _ @

try
{
    if (txtFilePath.Text == pdfFilepath )
    {
        byte [] b=File .ReadAllBytes (pdfFilepath);
        SqlConnection con1=Connection.Conn();
        SqlCommand cmd=new SqlCommand ("insert into tbl_Document(Company_Id,FileNo,PdfFile)values(@cid,@fno,@file)",con1);
        cmd .Parameters .AddWithValue("@cid",txtCompanyId.Text);
        cmd .Parameters .AddWithValue("@fno",txtFileNumber.Text);
        cmd .Parameters .AddWithValue("@file",b);
        con1.Open();
        cmd .ExecuteNonQuery();
        con1.Close();
    }
    else
    {
        MessageBox.Show("Please give a valid file address.");
        this.Dispose();
    }
}
catch
{ 
    MessageBox.Show("Unable to Process.");
    this.Dispose();
}

Why do you want the files to be stored in a database? 为什么要将文件存储在数据库中? A file system (which I'm sure the server in question also has) is much more suited to keeping and serving files. 文件系统(我确定所涉及的服务器也具有该文件系统)更适合保留和提供文件。

If the files must be in the database, then you'd probably just want to store them in a blob field. 如果文件必须在数据库中,那么您可能只想将它们存储在blob字段中。 Additional fields should be added to the table with data about the files, of course. 当然,应该将其他字段与有关文件的数据一起添加到表中。 File name, file type, maybe file size if you don't want to have to calculate it from the blob on the fly, maybe the user who uploaded it, the time it was uploaded, etc. 文件名,文件类型,文件大小(如果您不想从运行中的Blob中进行计算),文件的上传用户,文件的上传时间等。

At that point you'd interact with it just like any other database record in your application (skipping explanation of that for brevity, there's no shortage of tutorials on the subject), with the additional step of converting to and from byte arrays for the blob data. 到那时,您将与应用程序中的任何其他数据库记录进行交互(为简洁起见,跳过该说明,关于该主题的教程不乏),另外还包括为blob进行字节数组转换的额外步骤。数据。 Also, no shortage of examples . 另外, 不乏例子

But I have to drive back to my original question. 但是我必须回到我原来的问题。 Why put files in a relational database? 为什么要将文件放在关系数据库中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 c#将文件从远程计算机传输到终端服务器 - c# Transfer file from remote machine to terminal server 使用C#在Sharepoint而非服务器上的客户端计算机上下载文件 - Download files on client machine in sharepoint not the server using C# 如何使用 C# 在客户端计算机上下载文件 - How to download file on client machine using C# Java Server和C#客户端之间的套接字文件传输 - Socket File Transfer between Java Server and C# Client 机器到机器文件传输 - Machine to Machine File transfer 客户端计算机上的SQL Server数据库 - SQL Server database on Client machine 如何使用数据库部署C#Windows应用程序(安装文件)以及如何在客户端计算机上管理连接字符串 - How to deploy C# windows application (setup file) with database and how to manage connection string on client machine 在C#中的同一客户端计算机上区分两个用户 - Differentiating between two users on the same client machine in C# C#:客户端计算机是否需要安装SQL Server,同时连接到安装了SQL Server的其他计算机(服务器计算机) - C# :Does Client machine need SQL Server installed on it while connecting to other machine having SQL Server installed on it (the Server machine) 从服务器到客户端计算机C#执行远程应用程序 - Executing a remote application from server to client machine C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM