csharp,using System;,using System.Data.SqlClient;,,public class DatabaseConnection,{, private string connectionString = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;";,, public void Connect(), {, using (SqlConnection connection = new SqlConnection(connectionString)), {, try, {, connection.Open();, Console.WriteLine("Connection successful!");, }, catch (Exception ex), {, Console.WriteLine("Error: " + ex.Message);, }, }, },},
`,,请确保替换
myServerAddress、
myDataBase、
myUsername 和
myPassword` 为实际的数据库信息。Powered By Z-BlogPHP 1.7.3