SQL Server连接字符串
时间:2011-01-19 来源:草堂
使用OleDb进行连接
//标准连接方式 connectionStr = "Provider = sqloledb; Data Source = (local); Initial Catalog = databasename; User Id = ***; Password = ***"; //信任连接方式: connectionStr = "Provider = sqloledb; Data Source = (local); Initial Catalog = databasename; Integrated Security = SSPI";
注意:Integrated Security=true 用于 OleDb 提供程序时会引发异常。当将该属性改为true时,会引发异常,无法打开数据库连接。
使用SqlClient进行连接
SqlClient进行连接分为使用windows身份验证和使用SQL Server 身份验证方式。
-
使用windows身份验证
connectionStr = "Persist Security Info=False;Integrated Security=true;Initial Catalog=databasename;Server=(local)"; 或 connectionStr = "Persist Security Info=False;Integrated Security=SSPI;database=databasename;server=(local)"; 或 //Integrated Security=true 用于 OleDb 提供程序时会引发异常 connectionStr = "Persist Security Info=False;Trusted_Connection=True;database=databasename;server=(local)";
-
使用SQL Server 身份验证
connectionStr = "Persist Security Info=False;User ID=sa;Password=sa;Initial Catalog=databasename;Server=(local)";
相关阅读 更多 +