Presentation is loading. Please wait.

Presentation is loading. Please wait.

Adding a database to web service Add a database – Service->Add new item->SQL server database Add table to database – Server explorer->tables->Add new table.

Similar presentations


Presentation on theme: "Adding a database to web service Add a database – Service->Add new item->SQL server database Add table to database – Server explorer->tables->Add new table."— Presentation transcript:

1 Adding a database to web service Add a database – Service->Add new item->SQL server database Add table to database – Server explorer->tables->Add new table Add columns – Id (int, Identity specification=yes, allow nulls=no) – Name (varchar(50)) – PassWord (varchar(50)) Save and specify name (Users) You can add data or make SQL queries from server explorer – Table->Show table data (or New query)

2 Using session data To make the service functions use state data, define the functions with [WebMethod(Enablesession=true)] Now you can save session data between calls from same user To access this session data in code, create a property: bool IsAuthenticated { get { object state = Session["IsAuthenticated"]; if (state != null) { return (bool)state; } IsAuthenticated = false; return false; } set { Session["IsAuthenticated"] = value; }

3 Accessing the database To access a database, you need a connection string Select database file from server explorer and check properties->connection string string ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilenam e=C:\\... Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; Create sqlconnection with this connection string Create sql query to get access database Create sql command to run the query Open connection Create sqlreader for the response and run command.ExecuteReader() Or run command.ExecuteNonQuery();


Download ppt "Adding a database to web service Add a database – Service->Add new item->SQL server database Add table to database – Server explorer->tables->Add new table."

Similar presentations


Ads by Google