我是数据库的新手,我一直在学习一些教程,但我仍然坚持尝试使用我在Visual Studio中创建的精简版连接到我的数据库。
我试图通过以下方式连接数据库:
string connection = "Data Source=C:/Users/PLOW/Documents/Visual Studio 2012/Projects/File Name/File Name/Users.sdf";
// Making SQL connection
SqlConnection cn = new SqlConnection(connection);
cn.Open();
这样做我收到此错误:
"建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问..."
我试过了:
string connection = @"Data Source=|DataDirectory|\Users.sdf";
我得到同样的错误。我现在还不知道如何联系它。
这是我的连接字符串:
答案 0 :(得分:3)
当您使用精简版时,此处不需要SqlConnection
对象,而是使用SqlCeConnection
并添加对System.Data.SqlServerCe
的引用。
使用SqlCeCommand
代替SqlCommand
答案 1 :(得分:0)
如果是Connectionstring问题,则必须声明所需的参数以生成connectionstring
Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password