views:

43

answers:

3

I'm having some trouble getting personal contacts of some users I have in a database in SQL Server 2008.

I need to import into Outlook, so I can send an email to each one.

What is the best way for me to be able to connect to the database and get the contacts?

Thanks.

A: 

I don't understand if what you need is put your SQLSERVER contacts in your OUTLOOK or the other way around.

If you need to put your SQLSERVER contacts into OUTLOOK:

  1. Use .NET Framework
  2. Connect to SQL server
  3. Do a query to get all the contacts you need
  4. Put them into Outlook using OLE

If you need to put your OUTLOOK contacts into SQLSERVER

  1. Use .NET Framework
  2. Connect to Outlook using OLE
  3. Get all the contacts you need
  4. Put them into SQLSERVER using insert sentences
Pablo Santa Cruz
It is the first option, put the contacts into Outlook. I'll try what you said. :)
Filipe Costa
A: 

If all you need is sending emails to contacts you have in an SQL Server table, you don't need to go through the hassle of importing them into Outlook.

Have a look at xp_sendmail.
It should be possible to have your mails send with a "simple" transact SQL script.

Some other links that might be usefull

Lieven
But the mail can be more complex than simple text.I need also to attach a .doc file.
Filipe Costa
I haven't done that before but I wouldn't be surprised if it would be possible out of the box. If not, writing a program that extracts the email adresses from SQL Server, attaches a file and sends it off would (in my opinion) still be easier to do.
Lieven
A: 

You can easily import contacts into Outlook with a .csv file.

  1. Open SQL Server Management Studio
  2. Connect to database
  3. Goto Tools > Options > Query Results > SQL Server > Results to Text
  4. Under Output format choose Comma Delimited
  5. Confirm the "Include column headers" box is checked
  6. Click OK
  7. Open a new query window
  8. Run your query

You should see the results as comma-delimited text. You can either copy and paste to a .csv file or re-run the query and send the results to a file (Ctrl + Shift + F).

For a screenshot, see this question.

8kb