连接SQL Server数据库时,主要通过两种方式,Windows 身份认证和SQL Server 身份认证,数据库连接字符串也对应两种方式。具体如下:
<configuration>
<connectionStrings>
<!-- Windows 身份验证 -->
<!--<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=TestDB;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<!-- SQL Server 身份验证 -->
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>