如何在winforms应用程序中连接到远程sql server数据库?

时间:2022-04-22 10:23:52

The title speaks for itself. I'm building a winforms C# 2.0 app. Any tutorials or inspiring ideas?

标题不言而喻。我正在构建一个winforms C#2.0应用程序。任何教程或鼓舞人心的想法?

3 个解决方案

#1


ADO.NET is a big topic - but the keywords to search for here are SqlConnection, SqlCommand, SqlDataReader, etc. If you like DataSet (I'm not a fan, but some people love them), then the dataset designer will do a lot for you.

ADO.NET是一个很大的话题 - 但是在这里搜索的关键字是SqlConnection,SqlCommand,SqlDataReader等。如果你喜欢DataSet(我不是粉丝,但有些人喜欢它们),那么数据集设计师会做一个很适合你。

Another option is to use a .NET 2.0 web-service (asmx) for data access via a central app-server - making it a "smart client".

另一种选择是使用.NET 2.0 Web服务(asmx)通过*应用服务器进行数据访问 - 使其成为“智能客户端”。

With later .NET versions, WCF (.NET 3.0), LINQ-to-SQL (.NET 3.5), Entity Framework (.NET 3.5 SP1) and ADO.NET Data Services (.NET 3.5 SP1) become options.

随后的.NET版本,WCF(.NET 3.0),LINQ-to-SQL(.NET 3.5),实体框架(.NET 3.5 SP1)和ADO.NET数据服务(.NET 3.5 SP1)成为选项。

#2


There's not much difference between a local SQL Server instance and a distant one. You just set something like Server=sqlserver.remote-machine.com in your connection string.

本地SQL Server实例与远程SQL Server实例之间没有太大区别。您只需在连接字符串中设置Server = sqlserver.remote-machine.com。

#3


upgrade to C# 3.5 and use a Add->New Item->Linq to Sql Class... by far the easiest way i've ever seen, you can just drag from server explorer the tables you want... otherwise...

升级到C#3.5并使用Add-> New Item-> Linq to Sql Class ...到目前为止我见过的最简单的方法,你可以从服务器资源管理器中拖动你想要的表...否则......

it's much more difficult in 2.0 until you get your rythym down, As previous poster i'd recommend SqlConnection and SqlDataReader, etc. Before .NET 3.5 we had an ancient helper method that simply did something like the following

在你得到你的rythym之前在2.0中要困难得多,因为之前的海报我推荐SqlConnection和SqlDataReader等。在.NET 3.5之前,我们有一个古老的帮助方法,它只是做了类似下面的事情

DataAccessLayer dal = new DataAccessLayer("Connection String"); SQLDataReader sr = dal.getDataReader("SQLCOMMANDSTRING"); sr.Close(); dal.runProcess("SQLCOMMANDSTRING");

DataAccessLayer dal = new DataAccessLayer(“Connection String”); SQLDataReader sr = dal.getDataReader(“SQLCOMMANDSTRING”); sr.Close(); dal.runProcess( “SQLCOMMANDSTRING”);

etc..

for some specifics on how to use the SQL objects check the following: http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/2/

有关如何使用SQL对象的一些细节,请检查以下内容:http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/2/

#1


ADO.NET is a big topic - but the keywords to search for here are SqlConnection, SqlCommand, SqlDataReader, etc. If you like DataSet (I'm not a fan, but some people love them), then the dataset designer will do a lot for you.

ADO.NET是一个很大的话题 - 但是在这里搜索的关键字是SqlConnection,SqlCommand,SqlDataReader等。如果你喜欢DataSet(我不是粉丝,但有些人喜欢它们),那么数据集设计师会做一个很适合你。

Another option is to use a .NET 2.0 web-service (asmx) for data access via a central app-server - making it a "smart client".

另一种选择是使用.NET 2.0 Web服务(asmx)通过*应用服务器进行数据访问 - 使其成为“智能客户端”。

With later .NET versions, WCF (.NET 3.0), LINQ-to-SQL (.NET 3.5), Entity Framework (.NET 3.5 SP1) and ADO.NET Data Services (.NET 3.5 SP1) become options.

随后的.NET版本,WCF(.NET 3.0),LINQ-to-SQL(.NET 3.5),实体框架(.NET 3.5 SP1)和ADO.NET数据服务(.NET 3.5 SP1)成为选项。

#2


There's not much difference between a local SQL Server instance and a distant one. You just set something like Server=sqlserver.remote-machine.com in your connection string.

本地SQL Server实例与远程SQL Server实例之间没有太大区别。您只需在连接字符串中设置Server = sqlserver.remote-machine.com。

#3


upgrade to C# 3.5 and use a Add->New Item->Linq to Sql Class... by far the easiest way i've ever seen, you can just drag from server explorer the tables you want... otherwise...

升级到C#3.5并使用Add-> New Item-> Linq to Sql Class ...到目前为止我见过的最简单的方法,你可以从服务器资源管理器中拖动你想要的表...否则......

it's much more difficult in 2.0 until you get your rythym down, As previous poster i'd recommend SqlConnection and SqlDataReader, etc. Before .NET 3.5 we had an ancient helper method that simply did something like the following

在你得到你的rythym之前在2.0中要困难得多,因为之前的海报我推荐SqlConnection和SqlDataReader等。在.NET 3.5之前,我们有一个古老的帮助方法,它只是做了类似下面的事情

DataAccessLayer dal = new DataAccessLayer("Connection String"); SQLDataReader sr = dal.getDataReader("SQLCOMMANDSTRING"); sr.Close(); dal.runProcess("SQLCOMMANDSTRING");

DataAccessLayer dal = new DataAccessLayer(“Connection String”); SQLDataReader sr = dal.getDataReader(“SQLCOMMANDSTRING”); sr.Close(); dal.runProcess( “SQLCOMMANDSTRING”);

etc..

for some specifics on how to use the SQL objects check the following: http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/2/

有关如何使用SQL对象的一些细节,请检查以下内容:http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/2/