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