第一次C#链接数据库数据库
但愿在控制台界面上看到一个 success 就说明链接上了ui
这是个人代码spa
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; namespace DMSconfig { class Program { static void Main(string[] args) { SqlConnection conn = new SqlConnection(DMSconfig.Properties.Settings.Default.DMSstring); try { conn.Open(); System.Threading.Thread.Sleep(3000); Console.WriteLine("success"); } catch(Exception ex) { Console.Write(ex.Message); } finally { if(conn.State==System.Data.ConnectionState.Open) { conn.Close(); } Console.WriteLine("quit"); } Console.Read(); } } }
可是很不幸:code
这是为何呢?blog
我在stackoverflow上找到了和我有同样疑问的人的问题,并找到了正确答案。string
因而我也找到了对应字段并删除。it
而后再运行一次:io