Since you are using SQL Server, there are two more options available apart from the one that Gaffer mentioned.

The options are using ADOX and SQL-DMO. Read up on both and choose the one that suits you better. In my opinion SQL-DMO score way above ADOX.

Cheers!
Abhijit