Can';t使用C#Visual Studio连接到本地数据库

Can';t使用C#Visual Studio连接到本地数据库,c#,sql-server,database,visual-studio,visual-studio-2012,C#,Sql Server,Database,Visual Studio,Visual Studio 2012,我是数据库新手,我一直在学习一些教程,但我一直在尝试使用我在VisualStudio中创建的compact edition连接到我的数据库 我正在尝试通过以下方式连接到数据库: string connection = "Data Source=C:/Users/PLOW/Documents/Visual Studio 2012/Projects/File Name/File Name/Users.sdf"; // Making SQL connection SqlConnection cn =

我是数据库新手,我一直在学习一些教程,但我一直在尝试使用我在VisualStudio中创建的compact edition连接到我的数据库

我正在尝试通过以下方式连接到数据库:

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";
我得到了同样的错误。我不知道如何在这一点上连接它

这是我的连接字符串:


由于您使用的是compact edition,因此此处不需要
SqlConnection
对象,而是使用
SqlCeConnection
并添加对
System.Data.SqlServerCe
的引用


使用compact edition时,请使用
SqlCeCommand
而不是
SqlCommand

,因此此处不需要
SqlConnection
对象,而是使用
SqlCeConnection
并添加对
System.Data.SqlServerCe
的引用


使用compact edition时,请使用
SqlCeCommand
而不是
SqlCommand

,因此此处不需要
SqlConnection
对象,而是使用
SqlCeConnection
并添加对
System.Data.SqlServerCe
的引用


使用compact edition时,请使用
SqlCeCommand
而不是
SqlCommand

,因此此处不需要
SqlConnection
对象,而是使用
SqlCeConnection
并添加对
System.Data.SqlServerCe
的引用


使用
SqlCeCommand
而不是
SqlCommand

如果是Connectionstring问题,则必须声明生成Connectionstring所需的参数

Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password

如果是Connectionstring问题,则必须声明生成Connectionstring所需的参数

Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password

如果是Connectionstring问题,则必须声明生成Connectionstring所需的参数

Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password

如果是Connectionstring问题,则必须声明生成Connectionstring所需的参数

Data Source=servername;Initial Catalog=DbName;Integrated Security=True;User ID=userName;Password=password

可能重复的可能重复的可能重复的可能重复的可能重复的可能重复的测试它和工作。连接已建立。然而,这通过另一个错误实现:SqlCommand cmd=newsqlcommand(sqlAddUserPass,cn);sqlAddUserPass是insert querieI试图使用SqlCommand插入数据,但由于将连接更改为SqlCeConnection,因此出现重载错误。尽管如此,您还是回答了我最初的问题,因此我将其标记为已回答。请使用
SqlCeCommand
而不是
SqlCommand
,并通知我问题是否已解决:)对其进行了测试,结果有效。连接已建立。然而,这通过另一个错误实现:SqlCommand cmd=newsqlcommand(sqlAddUserPass,cn);sqlAddUserPass是insert querieI试图使用SqlCommand插入数据,但由于将连接更改为SqlCeConnection,因此出现重载错误。尽管如此,您还是回答了我最初的问题,因此我将其标记为已回答。请使用
SqlCeCommand
而不是
SqlCommand
,并通知我问题是否已解决:)对其进行了测试,结果有效。连接已建立。然而,这通过另一个错误实现:SqlCommand cmd=newsqlcommand(sqlAddUserPass,cn);sqlAddUserPass是insert querieI试图使用SqlCommand插入数据,但由于将连接更改为SqlCeConnection,因此出现重载错误。尽管如此,您还是回答了我最初的问题,因此我将其标记为已回答。请使用
SqlCeCommand
而不是
SqlCommand
,并通知我问题是否已解决:)对其进行了测试,结果有效。连接已建立。然而,这通过另一个错误实现:SqlCommand cmd=newsqlcommand(sqlAddUserPass,cn);sqlAddUserPass是insert querieI试图使用SqlCommand插入数据,但由于将连接更改为SqlCeConnection,因此出现重载错误。尽管如此,您还是回答了我最初的问题,因此我将其标记为已回答。请使用
SqlCeCommand
而不是
SqlCommand
,并通知我是否已解决:)