-->

.NET SqlConnection NIC usage

2019-06-13 16:42发布

问题:

Having a computer with multiple NICs, I need to specify somehow the one to use for the connection to SQL Server.

回答1:

Following on from @pzycoman, SqlConnection (and SQL OLEDB/SQL Server ODBC) has no explicit connection string semantic to express the bound NIC other than to specify the destination server host address (which in turn triggers the route metrics discussion). Splitting out services or applications onto different subnets can work - but equally can also generate the utilization asymmetry similar what you see today.

Another potential option would be NIC teaming if your adapters support it. Teaming software bonds multiple NICs into a single logical channel for increased throughput with less NetOps complexity. This happens at a much lower level in the OSI and as such is transparent to your applications and services.

Teaming used to be frowned on for a number of reasons (predominantly NLB issues and driver quality), but those have been largely mitigated in the last couple of years.

As always engineering mentality will help - test everything.



回答2:

If the NIC's have diffrent subnets, windows should automatically route the request through the right NIC (running "route print" from the command line will show you what gets routed where)



回答3:

The windows networking stack will figure out which nic to use to reach your database server. If you use the netbios name of your sql server in the connection string you might want to replace it with the IP adress (or dns entry) in the subnet that your preferred nic is on.