SQL Backup to Isolated storage from ADO.NET - c#

Is it possible to create an SQL server database backup using c# ADO.net and outputting the .BAK file to Isolated storage?
Thanks

What kind of isolated storage are you referencing?
How about:
create a stored proc to perform the backup.
BACKUP DATABASE [Foo]
TO DISK = N'\\server\directory\Foo.BAK' WITH NOFORMAT, NOINIT,
NAME = N'Foo-FullBackup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
call this stored proc on the SQL Server from your C# client code
depending on your needs (isolated storage?) use System.IO.File.Move() to move the .BAK file from its source to your destination.

No. Because there is no way to get access to the isolated storage PATH by program, you can not tell SQL Server to put things there.
Also, for anything but the most trivial applications, the size limit on isolated storage would be a joke compared what you need for a db backup.

Related

importing data from csv file in remote machine to postgresql table

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)

Have Sql SMO Delete Database Backup File

I have create a C# application that allows a database to be backed up and restored. It does this by first backing the database up to a local file on the Sql server using:
Backup backup = new Backup();
backup.Devices.AddDevice(Path.GetFullPath(backupFilePath), DeviceType.File);
...
backup.SqlBackup(server);
And then I create the new database by restoring from the backup file using:
Restore restore = new Restore();
restore.Devices.AddDevice(Path.GetFullPath(backupFileToRestoreFrom), DeviceType.File);
...
restore.SqlRestore(server);
After the new database has been created I want to delete the temp backup file that we created. Because I have admin rights on the Sql server box, I can delete the file on the remote server using:
File.Delete("\\SqlServer\C$\Backups\BackupFileToDelete.bak")
and it works. However, if somebody else who doesn't have rights on the Sql server box runs the app, it will throw an exception about not having permissions.
So is there a Sql SMO function that I can call to delete the backup file that was created on the remote Sql server?
If you delete the file using the xp_cmdshell then it will use the rights of the sql server instead of the rights of the person.
For example:
EXEC master..xp_cmdshell 'Del \\SqlServer\C$\Backups\BackupFileToDelete.bak', NO_OUTPUT
Here's the reference on xp_cmdshell
The important thing to note from that article is:
Because malicious users sometimes attempt to elevate their privileges
by using xp_cmdshell, xp_cmdshell is disabled by default. Use
sp_configure or Policy Based Management to enable it. For more
information, see xp_cmdshell Server Configuration Option.
Another possibility is to use SQLCLR, which is more secure than using xp_cmdshell. There's even a CodePlex project call SQLCLR File Functions that has the functionality written as stored procs for me. I think I'm going to see if I can convince our DBAs to go this route. The downside is that I believe the sprocs that this creates would need to be installed on every existing and new SQL Server that gets created; not much different than having to enable xp_cmdshell on every server though I guess.

Backup C# Windows application data

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

How to Export or Import complete database to another database using c#

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.

how to do attachments for each sql record in c#

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

Categories

Resources