如何将我的应用程序连接到数据库

时间:2022-09-27 03:01:33

I am trying to connect my app, developed in C# with a SQL Server database.

我正在尝试将使用C#开发的应用程序与SQL Server数据库连接起来。

The program is done! It's a mobile app.

程序完成了!这是一个移动应用程序。

My database is on C:\ProgramFiles\MyAppName\MyDatabase.sdf

我的数据库位于C:\ ProgramFiles \ MyAppName \ MyDatabase.sdf上

My code line is:

我的代码行是:

SqlConnection conn = new SqlConnection("server =" + iP.Text  +"," + port.Text + ";integrated security=false;Initial Catalog=" + DB.Text + ";User ID=" + userName.Text + ";Password=" + Pass.Text + ";Trusted_Connection=False;");

iP.Text = my IP (102.168.XXX.XXX)
port.Text = 49214 or 1433
DB.Text = "MyDatabase.sdf"
userName.Text= "sa"
pass.Text= "MyPass"

But when I try to connect it, the app says:

但当我尝试连接它时,该应用程序说:

er.Message = "El servidor SQL Server no existe o se ha denegado el acceso.

er.Message =“El servidor SQL Server没有任何存在的东西。

My server name is the same that my userName?

我的服务器名称和我的userName相同?

The application was made by someone else, I did nothing. But now I have to change some things and make it better. There is no manual

申请是由其他人提出的,我什么也没做。但现在我必须改变一些事情并使其变得更好。没有手册

Any idea? I really don't know what to do

任何想法?我真的不知道该怎么办

1 个解决方案

#1


3  

You are using Sql Server Compact Edition (SDF file) not Sql Server.
The classes needed to connect to this kind of database are different

您正在使用Sql Server Compact Edition(SDF文件)而不是Sql Server。连接到这种数据库所需的类是不同的

  SqlCeConnection conn = new SqlCeConnection(......)

The classes for Sql Server cannot parse correctly your connection string and you get the mentioned error. Of course, the classes for Sql Compact Edition require a reference to the appropriate DLL

Sql Server的类无法正确解析您的连接字符串,并且您得到上述错误。当然,Sql Compact Edition的类需要引用相应的DLL

 System.Data.SqlServerCe.dll

and the appropriate using statement at the beginning of your code file

以及代码文件开头的相应using语句

 using System.Data.SqlServerCe;

As last note, the connection string for a SQL CE database is simply

最后一点,SQL CE数据库的连接字符串很简单

 "Data Source = MyDatabase.sdf; Password ='<pwd>'"

doesn't seem possible to pass a specific user. See connectionstrings.com

似乎无法通过特定用户。请参阅connectionstrings.com

#1


3  

You are using Sql Server Compact Edition (SDF file) not Sql Server.
The classes needed to connect to this kind of database are different

您正在使用Sql Server Compact Edition(SDF文件)而不是Sql Server。连接到这种数据库所需的类是不同的

  SqlCeConnection conn = new SqlCeConnection(......)

The classes for Sql Server cannot parse correctly your connection string and you get the mentioned error. Of course, the classes for Sql Compact Edition require a reference to the appropriate DLL

Sql Server的类无法正确解析您的连接字符串,并且您得到上述错误。当然,Sql Compact Edition的类需要引用相应的DLL

 System.Data.SqlServerCe.dll

and the appropriate using statement at the beginning of your code file

以及代码文件开头的相应using语句

 using System.Data.SqlServerCe;

As last note, the connection string for a SQL CE database is simply

最后一点,SQL CE数据库的连接字符串很简单

 "Data Source = MyDatabase.sdf; Password ='<pwd>'"

doesn't seem possible to pass a specific user. See connectionstrings.com

似乎无法通过特定用户。请参阅connectionstrings.com