日期:2014-05-17 浏览次数:20414 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=Ture;User Instance=Ture")) ; { conn.open(); } Console.WriteLine("Open Success!!"); } } }
server==.\SQLEXPRESS;database=EpgInfo;user id=sa;password=sa; //database 数据库名 //id 数据库用户名 //password 密码
------解决方案--------------------
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=Ture;User Instance=Ture")) ;
{
conn.open();
Console.WriteLine("Open Success!!");
}
局部变量的作用域在大括号内,出了大括号就失去了作用,
像
try
{
int i=0;
}catch
{
}
i的作用域就在try的大括号内,try外面就无法访问了
------解决方案--------------------
Integrated Security=Ture修改为 Integrated Security=True