using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { try { //sqlserver身份验证 string sqlconn = "server=127.0.0.1;database=dingyingsi;uid=sa;pwd=Dys123456;"; //windows身份验证 //string sqlconn = "server=(local);database=keede1228;integrated security=SSPI;"; string select = "select id, username, password from [user]"; SqlConnection conn = new SqlConnection(sqlconn); Console.WriteLine("33"); conn.Open(); Console.WriteLine("11"); SqlCommand cmd = new SqlCommand(select, conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine("id:{0} username:{1} password:{2}", reader[0], reader[1], reader[2]); } conn.Close(); Console.WriteLine("22"); Console.ReadKey(); }catch(Exception e){ Console.WriteLine(e.Message); Console.ReadKey(); } } } }