I am trying to import a csv file into an SQL sever CE sdf database in a c# mvc3 web app. I understand that I need to read the csv file first and then transfer the file line by line into the sql database. I am very new to programming and need some guidence on how to do this.
I have heard Sql Compact Bulk Copy is the way to go, but I do not understand how to get the CSV file so it can be used by this. If anyone can shed some light on this I would be very greatful.
I hope this makes sense.
To create a new sdf File this is a litle example:
// if exists delete the file
System.IO.File.Delete("Test.sdf");
string cnn = "Data Source = 'TestDB.sdf'; LCID=1033; Password = <ThePassword>;";
SqlCeEngine ceEngine = new SqlCeEngine(cnn);
ceenngine.CreateDatabase();`
If you need to know more details you can read this MSDN(Create a Database by Using the Engine Object) http://msdn.microsoft.com/en-us/library/ms171966.aspx
Related
How to save a .VSD file into a FileTable in SQL Server 2012? And also need to retrieve and display the .VSD file on a web page?
Filetable column : file_stream varbinary(max)
Any help? Thank you.
Code used:
sfileName = "sample.vsd"
Dim fs As New FileStream(sfileName, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CInt(fs.Length))
VARBINARY(MAX) would be the correct data type to store binary data and you will want to use the FILESTREAM attribute. If you assume that this is the only type of file you will be storing in your table, then you are good. If you need to store multiple types of files you will want to add another column to capture the file type and then have your application display it correctly.
Check out the following post that should give you a better understanding. Article mentions SQL 2008 but it is applicable to 2012 and 2014:
http://blogs.technet.com/b/dataplatforminsider/archive/2008/04/14/sql-server-2008-makes-it-easy-to-manage-blobs-and-files.aspx
I have not found a way to save and retrieve the Visio (.vsd) file from the FILETABLE in SQL server 2012.
I tried to save the Visio file to the latest version of Visio (.vsdx) but it didn't work.
The work around for it is save the .vsd file to PDF or Image file. Then save the file to SQL Server FILETABLE using the code mentioned in my question.
How can i use copy command for bulk insertion of data into postgresql table from csv file present in remote machine using C#?
I've a front end in C# using which i need to load data into postgresql table from csv file. The database is in remote server and the csv file is in my machine.
Assuming the CSV file is on the machine running the C# program, you need to use COPY ... FROM STDIN. This is difficult to use directly from client drivers, but most of them support their own interfaces on top.
I'm guessing you are using nPgSQL since you didn't bother to mention what client you're using. If so, you can use NpgsqlCopyIn.
Not possible at all, unless you mount the remote machine on the postgres server. To copy postgres needs to be able to access the file locally.
You could try to scp the file from A to B, or parse the file yourself and do bulk inserts into postgres, ie:
create table file (structure of the file);
Read 100 lines
insert into tabe file
values (line 1)
,(line 2)
...
,line (100)
I'm designing a Windows application using C# in Visual Studio. I need to create back up button or something that would back up my data. How do I do that?
Simlpy create a back up for you data base. I should not be a big problem to triger that proces from your code.
check this sites:
How to Create Full Database Backup on MS SQL Server for a Database using T-SQL Backup Database command and SqlCmd Utility
How to: Create a Full Database Backup
Create a new store procedure similar to the content below and call it from your code.
Copy Code USE AdventureWorks2008R2;
GO
BACKUP DATABASE AdventureWorks2008R2
TO DISK = 'Z:\SQLServerBackups\AdventureWorks2008R2.Bak'
WITH FORMAT,
MEDIANAME = 'Z_SQLServerBackups',
NAME = 'Full Backup of AdventureWorks2008R2';
GO
Please help me to create a Export like Export and Import Opttion in in SQL Server 2005
Are you looking for something like this or this?
EDIT: Here is another example.
Here's an example.
Just send the needed sql statement to the server with a SqlCommand.ExecuteNonQuery().
For Backup:
BACKUP DATABASE [YourDatabaseName] TO DISK = N'FileName' WITH NOFORMAT, INIT, NAME = N'YourDatabaseName', SKIP, NOREWIND, NOUNLOAD, STATS = 10
For Restore:
RESTORE DATABASE [YourDatabaseName] FROM DISK = N'FileName' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
Or if you like just use (like already mentioned by others) the SqlBulkCopy class.
SqlBulkCopy can be used to import/export data to/from a SQL Server database.
Here is an article articles with example code:
www.codeproject.com/KB/database/Cs_CSV_import_export.aspx
Also SMO can be used as in this example code from Microsoft on how to backup and restore a database with C#: https://msdn.microsoft.com/en-us/library/ms162133.aspx.
I am developing a desktop application in c# & sql 2005. With candidate data entry form I want to provide option to attach required documents(in pdf format) wid data. Kindly let me know the best method. Thank you in advance.
Simply create a table that will contain the filename and server path for the file to be attached, then create a method to copy the attached file to the server location and store the relivant information (name and path) in the table. Use other methods to retrive the file from the server location when requested. Simple.
I personaly prefer to store the documents as BLOBs since server file structures and paths can change over time.
Well then unfortunately you have to either manage the file storage yourself using the servers file system, or you could store it in the db itself (IT WILL GET BLOATED!!!)
See sql server 2005 file storage
How To: Encrypt and Manage Documents with SQL Server 2005
OK, then for file management
see this example
File Manager Component