다음 코드는 예외입니다. 이 코드에서 잘못된 점이 무엇인지 말해 주실 수 있습니까? 양식을 여는 데 시간이 걸립니다. catch 블록의 메시지 상자는 양식을 열기 전에 표시됩니다. 내 데이터베이스가 실행 중이지만 왜 원활하게 실행되지 않는지 알 수 없습니다. 안내하시기 바랍니다 ...양식을 열기 전에 알 수없는 예외가 발생합니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IMS
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
// To set up a connection object
System.Data.SqlClient.SqlConnection con;
System.Data.OleDb.OleDbDataAdapter da;
private void Form2_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
// TODO: This line of code loads data into the 'iMSDataSet1.Part_Group'
//table. You can move, or remove it, as needed.
this.part_GroupTableAdapter.Fill(this.iMSDataSet1.Part_Group);
con.ConnectionString = "Data Source=.\\DataDirectory\\IMS.sdf;Password=ims;Persist Security Info=True";
//open up a connection to the database
try
{
con.Open();
}
catch
{
MessageBox.Show("Database Exception");
}
//Close up a connection to the database
con.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void AddPartGroup_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder(da);
//DataRow dRow =
}
}
}
답장을 보내 준 Jon에게 감사드립니다. 다음 오류가 발생하여 예외가 발생했습니다. _ "데이터베이스 예외 SQL Server에 연결하는 동안 네트워크 관련 또는 인스턴스 관련 오류가 발생했습니다. 서버를 찾을 수 없거나 액세스 할 수 없습니다. 인스턴스 이름이 올바른지, SQL Server가 올바른지 확인하십시오. (공급자 : SQL 네트워크 인터페이스, 오류 : 26- 오류 찾기 서버/인스턴스 지정됨) "_ 이 자습서에서 읽는 중입니다. http://www.homeandlearn.co.uk/csharp/csharp_s12p3.html . 그게 무슨 뜻인지 알 겠어? 내가 뭘해야 해? – m3nhaq
ConnectionString이 올바르지 않은 것처럼 보입니다 ... –
@ m3nhaq : 예외는 사용자가해야 할 일을 정확하게 알려줍니다. 인스턴스 이름이 올바른지, SQL Server가 원격 연결을 허용하도록 구성되었는지 확인하십시오. SQL Studio는 지정한 연결 문자열을 사용하여 탐색 할 수 있습니까? 기본적으로 데이터베이스에 연결하는 법을 배우기 전까지는 아무 것도 할 수 없으며 실제 코드 *와 관련이 없습니다. –