The Silver China Network (silverlightchina.net) has a "Silverlight and common Database Interoperability series" article, which describes methods and procedures for accessing different databases using Silverlight. However, for Silverlight access MS SQL is not comprehensive enough, here I want to explain how Silverlight accesses the MSSQL database stored procedures through WCF. Hope to be able to help you.
We want to implement, users enter user name and password, click the login button, pass the username and password to the server side, through WCF access to the MSSQL database, call stored procedures, on the server to match the user name and password, matching success, then return login success, otherwise, it is a failure.
Before the article starts, we need to do some preparatory work,
Development environment Requirements: VS2008 SP1, Silverlight 3 develop Tools for VS2008 SP1, client Silverlight 3 Runtime, MSSQL SP3;
Establish a routine database Silverlightdemo, create a new table in the database Users, including the following fields;
Add content to the users table, for convenience, the password is all used in plaintext, in the official project, the proposed password field encryption use.
Here, we verify the username and password, and there are two simple ways
First, the use of stored procedures to read the user name and password, and then on the server side of the user name and password matching checksum, if the search for matching data, then return login success, otherwise, it is login failure;
The second is to pass the username and password into the stored procedure, in the database stored procedures to determine, use SELECT statements to find, corresponding user name and password, if found matching results, then return the user ID, server-side received user ID, then return login success, otherwise, it is a failure;
In this case, it is mainly about Silverlight access to the database, so, for validation methods, not detailed description and explanation, if there is a problem, you can leave a message to me, we continue to discuss, here, I will use the first method of authentication. To do this, create a simple stored procedure:
1 CREATE PROCEDURE [dbo].[Login]
2 ( @UserName Varchar (30))
3 AS
4
5 Select cUserName, cPassword
6 From Users
7 Where cUserName = @UserName
8
9 RETURN
10
11 SET NOCOUNT ON