Silverlight access to the MSSQL database detailed

Source: Internet
Author: User
Tags mssql silverlight

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.