How to change the Database Connection of LINQ to SQL Class


Its very common that couple of developers are working on a single project. Me and one of my friend are also working on a .NET project. We are using LINQ to SQL class to query on the database. This is a desktop Windows Form project and we are maintaining our code as dumbest way possible. That is, when i update on any part, i just mail him the file and he replaces the file. So far so good.

Problem statement

But when I sent him my project, he couldn’t run the database queries. Because the connection string embed on the DataContext.dbml class was not changed. He couldn’t find a good way to change the connection string value. So I was searching for a better solution, and at last I found it today.


1. Double click on the DBML file of your project.


2. Now right click on the work area of the DBML file (Start sign in the image)
3. Expand the connection property and check the Data Source value. in my case, it is ‘Magicbox’ since it is my machine’s server name
4. If your server is not in mentioned, it means, you need to create another connection between your server and the DBML file. So, click on the ‘New; displayed in the image
5. Put your server name or click on the combo box (the arrow sign)
6. If your server name is not displayed after clicking on the combo, please write the name by your own ( my server’s name is not showing also)
7. Now click the database name combo box at the bottom side of the window. You will see the database names attached with your server
8. Select the database and click ‘Test Connection’ button. you will get a success message is connection succeed. Now close the success message and press OK button at the bottom of the page
9. Now if you click the connection combo again, you should see the just added database connection as the item of the combo
We now just change the database connection value from the properties of the DBML file and working fine.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s