user1438082
user1438082

Reputation: 2748

Specifying a network adapter for SqlConnection

I have 2 network cards in my machine:

  1. Network A auto-assigns the IP address.

  2. Network B is where a SQL Server is present.

When I connect using C#, the connection is intermittent. Can I specify my C# code to use a specific network adapter?

SqlConnection myConnection = new SqlConnection(
                                 "user id=username;"
                               + "password=password;"
                               + "server=serverurl;"
                               + "Trusted_Connection=yes;" 
                               + "database=database;"
                               + "connection timeout=30");

Upvotes: 1

Views: 793

Answers (1)

Yury Schkatula
Yury Schkatula

Reputation: 5369

In common scenario, you can't choose a network adapter to manually route outgoing traffic as this can breach your security. Just google for "strong host model" and "weak host model" (it depends on OS version for Windows and distribution origin for Linux).

For example, this is good overview on this matter: https://blogs.technet.microsoft.com/networking/2009/04/24/source-ip-address-selection-on-a-multi-homed-windows-computer

So, after all, you have nothing to do with network card selection. And if your connection is non-stable, you have to troubleshoot the network (router malfunction, throughput overload, firewall inspection delay etc.).

Upvotes: 1

Related Questions