C# ado.net 测试带实例名的sqlserver
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello中国"); SqlConnection conn = new SqlConnection(@"server=sm-pc,1433\sql2008;uid=sa;pwd=Admin12345;database=dbname"); SqlCommand cmd = new SqlCommand("SELECT * FROM user where user_code LIKE 'ad%'", conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while(dr.Read()){ string acctId = dr["u_id"].ToString(); Console.WriteLine(acctId); } conn.Close(); Console.ReadKey(); } } }
http://www.connectionstrings.com/sql-server-2008