How to connect to remote SQL Server database using Visual C#?

15,522

Solution 1

You need to investigate the SqlConnection, SqlCommand and possible SqlDataReader and SqlDataAdapter components in .NET (see the MSDN online docs).

Once you have that, you need to define your connection string - check that site link for a huge selection and explanation of connection strings.

Then you basically connect using:

using(SqlConnection conn = new SqlConnection('your connection string here'))
{
    conn.Open();
    // do stuff
    conn.Close();
}

and you can do stuff in various ways, e.g. by filling data sets, reading values etc.

Read the MSDN ADO.NET Overview to get started! Or Google for "ADO.NET tutorial" - you'll find tons of links.

Solution 2

The answer can be found here -

Connect to remote MySQL database with Visual C#

Also, read up and download from here - http://dev.mysql.com/downloads/connector/net/5.2.html

Solution 3

In the eye of MS SQL Server it is no difference where your SQL Server is located. All you need is to make sure you have access that server in terms of IP and Port number.

Share:
15,522
Ivan Stoyanov
Author by

Ivan Stoyanov

I am interested in software development.

Updated on June 05, 2022

Comments

  • Ivan Stoyanov
    Ivan Stoyanov almost 2 years

    I am creating a Windows forms application and my SQL Server database is on a remote server. How can I connect to it using Visual C# and ADO.NET?