C # Link database: SQL Server 2008

Source: Internet
Author: User

Learn C # programming yourself, and in WinForm programming, code tests the connection database.

Now the database that is being tested in SQL Server can log on with the specified user name and password.

, the computer name is administrator, the DB instance is sqlexpress, the login name is testuser, the password is set to 123456, and the User Name Mapping database is TestDB.

Code for the linked database:

//Windows Authentication Mode string Connectionstringtest=@ "Data Source=Administrator\sqlexpress;initial Catalog=Testdb;integrated Security=SSPI; ";//Establish a trust connection (the specific meaning differs from the other way to learn) string Connectionstringtest=@ "Server=Administrator\sqlexpress;initial Catalog=Testdb;integrated Security=True ";//standard way to connect a database to a Web site string connectionstringtest=@ "Server=administrator\sqlexpress;Database=TestDB;UserId=Testuser;password=123456";//standard way for applications to connect to a database string connectionstringtest=@ "Data Source=administrator\sqlexpress; Initial Catalog=TestDB;UserId=TestUser Password= 123456;";

Code to link, disconnect, and release resources:

= new SqlConnection (connectionstringtest); try{           Conn. Open ();
MessageBox.Show ("Database link succeeded! "," Prompt ");} catch (Exception e) { = e.message;} finally{ Conn. Close (); Conn. Dispose ();}

C # Link database: SQL Server 2008

Related Article

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.