I have written a simple program(Winf开发者_如何学JAVAorms.NET), that selects a random word from a dictionary (DB table) everyday. When the DB is embedded its fine, but if I want to make the program take the data from a remote server.
I suppose I have to put the ip address of SQL Server host into my connection string, but if host allows remote connections.
Or I will make a WebService that sends the data and my desktop app will consume the WebService. Would it be a right approach.
If yes, any leads on how to consume webservice from WinformsApp.
Thanks in advance
If using winforms and the server accepts remote connections, then indeed you just need to put the SQL Server instance name or IP address in the connection string. Using a web service has the advantage that allows your data to be accessed from other environments that do not support direct database connections, such as a Silverlight application; but if you are just using winforms, I would rather stick to direct database connections to keep things simple.
A webservice is a better approach for a number of reasons - because it better protects your database and because its more likely to work well given that http (as a protocol) is more likely to be accessible from you client.
Web services (or better WCF services) are straightforward to create and consume from a Win Forms app if you're developing with Visual Studio and have control over both ends.
First create your service application - details depend on what you want to do, then from within your forms application you add a service reference (although again it depends on which tools you're using).
精彩评论