连接字符串不起作用,无法读取文件位置
Connection String not working, cannot read file location
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename="c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf";Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter(@"SELECT Student_ID, Name, Course_ID, Course_Name, Study_Program FROM Students CROSS JOIN StudentCourse", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
这部分代码显示错误:
c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf";Integrated Security=True;Connect Timeout=30");
之后出现这个错误
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Format of the initialization string does not conform to specification starting at index 28.
似乎是文件夹名称周围的双引号引起了问题。您在数据源处打开它们,它们在文件夹名称处关闭它们。我会先尝试删除文件名周围的双引号,我认为连接字符串中不需要它们。
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf;Integrated Security=True;Connect Timeout=30");
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename="c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf";Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter(@"SELECT Student_ID, Name, Course_ID, Course_Name, Study_Program FROM Students CROSS JOIN StudentCourse", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
这部分代码显示错误:
c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf";Integrated Security=True;Connect Timeout=30");
之后出现这个错误
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Format of the initialization string does not conform to specification starting at index 28.
似乎是文件夹名称周围的双引号引起了问题。您在数据源处打开它们,它们在文件夹名称处关闭它们。我会先尝试删除文件名周围的双引号,我认为连接字符串中不需要它们。
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf;Integrated Security=True;Connect Timeout=30");