MS SQL Server - Bulk Insert Across a Network - sql-server

I have an application that uses MS SQL Server for which I'll need to do a bulk insert from a file. The sticking point is that the database and my application will be hosted on separate servers. What is the best way to do a bulk insert across a network? Two ideas I'd come up with so far:
From the app server, share a directory that the db server can find, and do the import using a bulk insert statement from the remote file
Run an FTP server from the db server - when the import is performed, simply ftp the file to the db server and do the import using a bulk insert from the local file (I am leaning towards this option).
Can anyone else tell me if there is a better way to do this, or if not, which one makes the most sense, and why?

I've done it before, and tried both options.
In the end, I did the opposite of choice 1. Share a directory on the DB server that the app can find. You don't have to deal with bandwidth issues during the bulk insert.
The FTP server option works if you're particularly concerned with security or transferability.
A final option (be very careful) is to use DTS with a localized SQL server. It might be more secure. If you do it wrong, it'll be much less efficient.

I'm still looking for a way to do this in MS SQL, but what I did in MySQL was to save the CSV as a BLOB in a temporary table, run SELECT ... INTO DUMPFILE in a directory local to the DB server, then run the regular LOAD DATA statement on that local file (EDIT: I feel I should point out, this was before LOAD DATA LOCAL was available).
I think spWriteStringToFile will do it.
EDIT: I'm on to something.
comm.CommandText = #"EXEC spWriteStringToFile #data, 'c:\datadumps', 'data.csv';
BULK INSERT my_table FROM 'c:\datadumps\data.csv';";
comm.Parameters.AddWithValue("data", File.ReadAllText(path));
comm.ExecuteNonQuery();

If the file is small enough then the ftp option may work (you will have a duplicate in your db box). However I don't see much of a problem to do option 1) if you have a gigabit network between the two with a single hop.

I am not sure about 2k08 as there are some additional utilities to copy files between servers. FTP will be the faster of the two, because it doesn't use the window's file system to transfer the file. (there is overhead, but unless the file is large it might be negligible). There are other advantages to not using a share, such as the remote server with the file crashing mid-access.
I disagree with cmartin about adding an open share to the db server. Generally you don't want to open file shares to the db server as it is generally considered a security risk, and a lot of places won't allow it. That being said it would negate you having transfer the file to another location to use the bulk import.

Actually you can place the file at both the Application and Database server.
Both files must be the same path. From the Application server, the purpose is only for selection. The Database server is for the bulk insert.
This is what I did for my customer and they also agreed with this simple trick.

Related

Prevent database file from copying

I want to deploy a .NET application on client machine. I don't know how to protect my database .mdf and .ldf files from copying. Is there any way to prevent them also from copying these files? I'm using SQL Server 2008 R2.
Short answer NO!
If they own that server there's little you can do.
If they are consuming your DB means they have a connection string to it. By using that connection string they can do a lot of things.
You can try to cryptography your DB, create just a handsome of users with specific crud operations permissions, etc.
But if they own the server they virtually have ultimate control over anything running on it.
And by the merit of just coping files, they can do what they want.
If you want to provide a service/application and don't want to provide clients to copy your precious data you ill need to host that by yourself or by a trustworthy third party.

How to make a test database from AS400

For SQL Server, we are able to send over the db for the most part pretty easily to offshore staff.
Is this possible with the AS/400 or they can only VPN in to work?
Every database engine has a slightly different version of SQL. DB2 for i at V5R4 has differences to DB2 LUW 9.7 and both are different to SQL Server and MySQL at any version. So the quick answer is no, you can't simply make a copy of a DB2 for i database and run it on MySQL or SQL Server. You'd normally do exactly as you are doing with SQL Server: Have one machine here and another machine there and unload/reload the data as needed.
Having said that, the differences between SQL dialects are not usually crippling. Use the IBM Navigator for i and extract all of the DDL for the IBM database, then try to execute the DDL on the SQL Server machine. You'll have some syntax problems, but you should be able to work them out with someone who is knowledgeable in both dialects. Keep track of the changes to the DDL because you'll need them in order to extract the data from the IBM side.
Once you have the empty database created on the new machine, it's time to extract out the data. Write some CL programs to do CPYTOIMPF to generate CSV files or flat files or whatever it is that SQL Server wants in order to import properly. Then FTP that data to the new machine and write some scripts to do the import.
As you can tell, this is not going to be a simple process and it will take some time to develop and debug. I'd go with having the offshore staff using a VPN to the local IBM machine.
The easiest way I can think of would be to create a Save File (SAVF) then FTP that save file to the other IBM i and [restore it] (http://pic.dhe.ibm.com/infocenter/iseries/v6r1m0/index.jsp?topic=/cl/rstobj.htm).
In the PC world this is similar to zipping up a directory, FTPing it to another machine and then unzipping it.
If this isn't what you mean, can you elaborate on what you're wanting?
The offshore site probably has their own SQL Server, probably running the same version as you.
But unless they also have an IBM Power System running the same release of IBM i, then they will most likely need to access your system.

Easiest way to copy Oracle DB to test DB on same server?

I'm used to working with SQL Server and when I want to copy a DB there, I just need a handful of clicks in the wizard and voila...a complete copy of the DB, without taking the source DB offline.
We now also have an Oracle 11g because some machines require it, and I want to make a copy of the database. Just a copy on the same server, to use as a test DB for my software development.
All instructions that I find are pages full of steps, using RMAN or not, you have to write scripts, use command line stuff...I'm amazed at how inefficient such a common task is when using Oracle.
Aren't there any easy ways of copying a DB? Maybe just exporting everything to a SQL file, then editing it to use another DB name, and then executing it again?
I see that in SQL Developer you can choose 'Database Copy...' from the Tools menu, but it asks a destination connection. How can I select a destination when creating the destination DB is the whole point of running the wizard? Or is a connection not the same as a DB?
Thanks for helping me out here!
You're generally going to need a new database to copy the data to, and the data could be copied with datapump export/import. There aren't many ways of getting around that I'm afraid, but one option that you might consider is to make more use of VM's such as Oracle's own VirtualBox, as they can be cloned very easily with an absolute certainty of byte-by-byte fidelity.
Incidentally, one problem in making logical copies (via export/import) of a database is that it's easy to end up with a different physical pattern to the table and indexes, which can lead to unexpected differences in query optimisation.

How to transfer data from a SQL Server Database to a Oracle Database

The current application I'm working lets call X is an archiving application for the data kept another application say Y. Both are very old applications developed about 8 odd years back. So far in my reading of the documentation, I have learnt that the process to transfer data used is that, the SQL Server Database Tables snapshot is created in flat files and then this flat files are ftp'd to the correct unix box where through ctl various insert statements are generated for the Oracle Database and that's how this data is transferred. It uses bcp utility. I wanted to know if there is a better and a faster way this could be accomplished. There should be a way to transfer data directly, I feel the whole process of taking it in files and then transfer and insert must be really slow and painstaking. Any insights???
Create a DB Link from your Oracle Database to SQL Server database, and you can transfer the data via selects / inserts.
Schedule the process using DBMS_SCHEDULER if this needs to be done on a periodic basis.
you can read data from a lot of different database vendors using heterogeneous services. To use this you create a service on the Unix box that uses - in this case - odbc to connect to the SQL Server database.
You define this service in the listener.ora and you create a tns alias that points to this service. The alias looks pretty normal, except for the extra line (hs = ok). In your database you make a database link that using this tns alias as connect string.
UnixODBC in combination with the FreeTDS driver works fine.
The exact details vary between releases, for 10g look for hs4odbc, 11g dg4odbc.

SQL Server 2008 Database (How to lock it from copying and attach it in another machine)

I have a database with data that i don't want anyone to copy around.
Now, how can i prevent other users to have access in the local machine, but whenever i want to work with, i am allowed.
And another issue I'm thinking, how can i lock the DB so if someone copy the .mdb file and try to attach it on another machine he/she couldn't see a thing?
There are many different kinds of encryption options available in SQL Server. If you don't want to have to re-write your application then the new feature in SQL Server 2008 called Transparent Data Encryption (TDE) is for you. It means you can encrypt the data files to prevent unauthorized users getting at the data from a backup or by copying the data files.
This MSDN link should be enough to get you started.
You probably want to use database encryption to achieve this. Then the mdb file will be useless.
Some links
http://blog.sqlauthority.com/2009/04/28/sql-server-introduction-to-sql-server-encryption-and-symmetric-key-encryption-tutorial-with-script/
http://msdn.microsoft.com/en-us/library/cc278098.aspx
http://technet.microsoft.com/en-us/library/bb510663.aspx
http://support.microsoft.com/kb/316898

Resources