Question : importing mdb into sql server 2008 with vb6

I download access database files daily from an ftp server.  I need to import these records into sql server 2008 on a daily basis.  I want this totaly automated.  How can I do this with vb6?

Thanks in advance,


Answer : importing mdb into sql server 2008 with vb6

If you create a SSIS package and use a ForEach task you can loop thought the files in a folder that end with .mdb. That way it won't matter what the filename is called. You put that filename that it just found into a variable and then you can map that variable to your connection and send the data to the sql server/oledb destination and import the data that way.

Take a look at this. There's an MDB that as one table in it. A SQL database (2005) named MDBtoSQL that has one table in it with the structure the same as the mdb. The MDB and ProcessedFolder are in the same directory as the project. The stuff is meant to run on C:\Projects but that's easy to change (change the variables and you'll be golden)Then a mockup of what a ssis package could be.

3 variables, 3 connection managers. Variables are named so you know what goes in them. The Connection managers are all dynamic. On the Expressions option click the [...] and take a look to see what they're bound to.

The package starts with a ForEach container to get the file out of the folder. Manually input the folder where the file will be coming. And then the files will be coming as *.mdb. Now click on the Variable Mappings tab and you'll see that the file that was found is mapped to the user variable MDBFileName.

On the data flow task open that one up. The connection manager is the MDB Connection manager and then you click on the "name of table or view" and select "MyTable". Click on the columns tab to make sure everything is coming over as expected. Then click on the SQL Server oldeb destination. Select the SQL Server connection manager and then click the drop down and select "MyTable". Click on the "mappings" tab and make sure that everything is mapped correctly. if it's not, click on the name on the left and drag the line to the matching name on the right.

Since you're going from Access to SQL you have to do a data transformation (via derived column) to get the types out of what Access brings in.

Then (back to the control flow) - you're going to want to put the processed mdbs into a folder. So that task moves the file and puts it in a folder (file destination configured to the ProcessedFolder variable).

Now to get the files down every day from the ftp site - you're going to want to use the FTP task control flow item. Click on "New Connection under "FTPConnection". It will bring up a box where you put your ftp info in. Under the File Transfer tab you can put in the remote path where the ftp comonent is supposed to be looking.  On the Local Parameters box, click IsLocalPath = True. Select the MDBPath as your local path. That will put the file where it needs to go ( and the place where the ForEach component will read from).

You could schedule this on a schedule task or SQL job to make it run daily at whatever time you want it to.

But that's how you would do it in SSIS. Not too bad actually.

Okay..little tricky getting these files through. Name the "pdf" extension to ".database". Name the "txt" extension to ".dtproj" And name the "xls" extension to ".dtsx"

Random Solutions  
programming4us programming4us