Thursday, November 6, 2008

How do I set up a Data Connection in Visual Studio 2008?

It depends on where the data comes from, SQL Server, IBM DB2, MS Access etc.

Here is what you do for SQL Server 2008.

Step 1: Open Visual Studio 2008
            Click View | Server Explorer
            Click on Connection as shown.












The Add Connection window shows up
























Step 2: Click on the Change...button




The Change Data Source window gets displayed.

















Step 3: Highlight Microsoft SQL Server
            Click OK




Step 4: Click on the Refresh button
            Then click on the drop-down button
The SQL Servers on your machine should show up as in the figure
            Choose the SQL Server 2008 as shown by highlighting Hodentek2\SANGAM
























Step 5: Assuming the SQL Server 2008 is to be Windows Authenticated
       Click on the drop-down handle for 'Select or enter a database name:"
       Select AdventureWorksDW2008 as shown

.





















Step 6: Click on Test Connection button
You should get the following message














Step 7: Click OK to the message and close the Add Connection window.
You are done.

Now you will see your connection in the Data Connections folder in Server Explorer
Now you can access Tables, Views, Stored Procedures and Functions within the Visual Studio IDE






















Well I have a number of other connections in my VS 2008 IDE.

7 comments:

Vijay Reddy Chennadi said...

Hi..
I hava VS2008 SP1, and Sql Server 2005 installed in my system. I am having problem in connecting from VS. I get an error like this...

Unable to add data connection.
Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral,PublicKayToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

Can you please help me out. Please mail me @ vijay.reddy.chennadi@gmail.com
Thank you very much..

Jayaram Krishnaswamy said...

Can you connect to the server in the Management Studio?

ADITYA said...

sir...can plz..Let me know how to do this...:
this derver version is not supported.
only servers up to microsoft SQL Server 2005 are supported.

ADITYA said...

this server version is not supported.
only servers up to microsoft SQL Server 2005 are supported.

Jayaram Krishnaswamy (mysorian) said...

Give me few more details about what you are trying to do.Perhaps I can help you.

Sunil Thapa said...

I have done this.It has created app.conf file and dataset. Now how to store data in database using this data connection.

Jayaram Krishnaswamy said...

This articles should help you:
http://www.codeproject.com/Articles/245612/Creating-a-Database-Project-with-Visual-Studio

http://www.codeproject.com/Articles/8157/ADO-NET-SQL-Connection