简体   繁体   中英

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. 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. 2. Allow direct access to DB over IP address and create your sql connection directly from desktop client app and access the required data.

Option #1 is recommended for scalability and security reasons .

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

If you want to use an ODBC DSN on the remote machine

<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

<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

<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

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM