问题
I have SQL Server Database which is present on some web server.I made a WPF or Windows form Desktop application using C# .Net.I want to retrieve data from sql server database in my desktop application as per end user requirements on its own local PC.Give me best way and best solution regarding security and accessing data.
回答1:
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 .
回答2:
B/S or C/S has no relation of Data Access.What you need to do is just load the data from DB and wrap then parse it to your component.Whether you want to know is how to control the database links or concurrency and its like ?
回答3:
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>
来源:https://stackoverflow.com/questions/40988693/how-i-retrieve-data-from-sql-server-database-hosted-on-a-web-server-in-my-deskto