Connecting to SQL Server Using an IP Address

Use the Network Address and Network Library attributes of the connection string.

The solution creates and opens a connection to a SQL Server using its IP address. Information about the SQL Server is displayed from the properties of the SqlConnection object.

 using System;

using System.Data.SqlClient;
   namespace ConnectIPAddressSqlServer
    class Program
        static void Main(string[] args)
            string connectString =
                "Network Library=dbmssocn;Network Address=;" +
                "Integrated security=SSPI;Initial Catalog=AdventureWorks";
             using (SqlConnection connection = new SqlConnection connectString))
                connection.Open(  );
                 // Return some information about the server.
                    "ConnectionState = {0}\nDataSource = {1}\nServerVersion = {2}",
                    connection.State, connection.DataSource,
             Console.WriteLine("\nPress any key to continue.");
            Console.ReadKey(  );



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

%d bloggers like this: