简体   繁体   English

如何从桌面应用程序中Web服务器上托管的SQL Server数据库中检索数据?

[英]How I Retrieve Data from SQL Server Database hosted on a Web Server in my desktop application?

我有一些Web服务器上存在的SQL Server数据库。我使用C#.Net创建了WPF或Windows窗体桌面应用程序。我想根据最终用户在其自己的本地PC上的需求从我的桌面应用程序中的sql server数据库中检索数据。给我有关安全性和访问数据的最佳方法和最佳解决方案。

You have 2 options. 您有2个选择。 1. Write the business logic layer which resides on the web-server and communicates with DB to serve the required data based on requests coming from the desktop client application. 1.编写驻留在Web服务器上并与DB通信以基于来自桌面客户端应用程序的请求来提供所需数据的业务逻辑层。 2. Allow direct access to DB over IP address and create your sql connection directly from desktop client app and access the required data. 2.允许直接通过IP地址访问数据库,并直接从桌面客户端应用程序创建您的sql连接并访问所需的数据。

Option #1 is recommended for scalability and security reasons . 出于可伸缩性和安全性原因,建议使用选项#1。

B / S或C / S与数据访问没有关系。您需要做的只是从数据库中加载数据,然后将其包装然后解析到您的组件中。您是否想知道如何控制数据库链接或并发性,以及就像是 ?

If you want to use an ODBC DSN on the remote machine 如果要在远程计算机上使用ODBC DSN

<pre>
oConn.Open "Provider=MS Remote;" & _
           "Remote Server=http://myServerName;" & _ 
           "Remote Provider=MSDASQL;" & _
           "DSN=AdvWorks;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword" 
 </pre>

If you want to use an OLE DB Provider on the remote machine 如果要在远程计算机上使用OLE DB提供程序

<pre>
oConn.Open "Provider=MS Remote;" & _ 
           "Remote Server=http://myServerName;" & _
           "Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=c:\somepath\mydb.mdb", _
            "admin", ""
 </pre>

If you want to use an OLE DB Provider on the remote machine 如果要在远程计算机上使用OLE DB提供程序

<pre>
oConn.Open "Provider=MS Remote;" & _ 
           "Remote Server=http://myServerName;" & _
           "Handler=MSDFMAP.Handler;" & _
           "Data Source=MyAdvworksConn"
The corresponding entry in the \winnt\Msdfmap.ini file would be:

[connect MyAdvworksConn]
Access = ReadWrite
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;
           Data Source=mydb.mdb;
           User Id=admin; 
           Password="               (put all of this on single line!)
 </pre>

MS Remote - SQL Server If you want to use an ODBC DSN on the remote machine MS Remote-SQL Server如果要在远程计算机上使用ODBC DSN

<pre>
oConn.Open "Provider=MS Remote;" & _
           "Remote Server=http://myServerName;" & _ 
           "Remote Provider=MSDASQL;" & _
           "DSN=myDatabaseName;" & _
           "Uid=myUsername;" & _
           "Pwd=myPassword" 

If you want to use an OLE DB Provider on the remote machine

oConn.Open "Provider=MS Remote;" & _ 
           "Remote Server=http://myServerName;" & _
           "Remote Provider=SQLOLEDB;" & _
           "Data Source=myServerName;" & _
           "Initial Catalog=myDatabaseName;" & _
           "User ID=myUsername;" & _
           "Password=myPassword"

If you want to use an OLE DB Provider on the remote machine

oConn.Open "Provider=MS Remote;" & _ 
           "Remote Server=http://myServerName;" & _ 
           "Handler=MSDFMAP.Handler;" & _
           "Data Source=MyPubsConn" 
The corresponding entry in the \winnt\Msdfmap.ini file would be:

[connect MyPubsConn]
Access = ReadWrite
Connect = "Provider=SQLOLEDB;
          Data Source=myServerName;
          Initial Catalog=myDatabaseName;
          User ID=myUsername;
          Password=myPassword"       // (put all of this on single line!)
</pre>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从Sql Server推送到桌面应用程序 - Push data from Sql Server to desktop application 使用托管的Web应用程序连接到SQL Server数据库 - Connecting to SQL Server Database using a Hosted Web Application 从SQL Server数据库检索更多数据 - Retrieve more data from a SQL Server database 如何在 C# 中从 SQL Server 数据库中检索数据? - How to retrieve data from a SQL Server database in C#? 我可以像使用内置数据库一样使用桌面应用程序部署SQL Server Express吗? - Can I deploy SQL Server Express with my desktop application just like builtin database? 如何在C#中使用数据表从SQL Server检索表中的数据 - How do I use the datatable to retrieve data in my table from SQL Server in c # 我可以在没有Web服务的情况下从C#桌面应用程序连接到Sharepoint上的SQL Server数据库吗? - Can I connect from my C# desk top application to an SQL Server database on Sharepoint without a web service? 如何在未安装SQL Server的计算机上使用其Sql Server数据库运行桌面应用程序 - How to run desktop application with its Sql Server database on a machine that have not SQL server installed 从服务器托管应用程序时如何获取用户文件的本地桌面路径? - How to get the local desktop path of the users file when the application is hosted from server? 托管在另一台计算机上的Web应用程序可以在不将数据发送到服务器的情况下从本地.NET应用程序接收数据吗? - Can a web application hosted on another machine receive data from a local .NET application without sending data to the server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM