Linq数据库连接问题

当使用连接字符连接本地数据库时,使用string connectionString = "Server=localhost;uid=sa;pwd=sa;database=DataBase;Integrated Security=SSPI"测试正常,但连接远程数据库会抛出“未与信任 SQL Server 连接相关联”错误。应更改连接字符串为:“Data Source=192.168.4.23;Initial Catalog=DataBase;Persist Security Info=True;User ID=sa;Password=sa”测试通过。
主要原因在于:
(1)用户名称 uid=>User ID;
(2)密码 pwd=>Password
在使用ADO.Net进行数据连接时,在字符串格式上,要求不是十分严格,而使用Linq进行数据库访问,则要求更严格一些。
顺便解释下连接字符串属性含义:
主要介绍如下两个属性
Persist Security Info属性的意思是表示是否保存安全信息,其实可以简单的理解为"ADO.Net在数据库连接成功后是否保存密码信息",True表示保存,False表示不保存。默认为False.
Integrated Security属性的意思是表示是否使用Windows身份认证,Integrated Security = Ture使用windows身份认证,但是,只有当Integrated Security = SSPI将适用于OleDb .NET Framework 数据提供程序。为 ConnectionString 设置 Integrated Security=true 将引发异常。
posted @ 2007-11-15 16:22  Mashimaro  阅读(3665)  评论(0编辑  收藏  举报