VS2005 C# ASP.NET과 SQL Server 2005를 사용하고 있습니다.가져 오기 전에 파일 내용을 확인하십시오.
Excel 데이터를 가져 오는 기능이 있습니다. 내부의 데이터가 부적절한 상황을 만났을 때 SQL Server DB가 다운됩니다.
예. SELECT [Username], [Userlist $]에서 [Password] -> Excel 스프레드 시트에 [Username]이 (가) 한 열 또는 열 아래에 있으면 서버가 중단됩니다.
E.G.
업로드하기 전에이 파일의 오류를 확인하는 방법을 어떻게 알 수 있습니까? 확인을 위해 if
else
진술을 선호하십시오.
주어진 도움이나 예제를 이용해 주셔서 감사합니다. 다음은
는 엑셀 업로드 내 코드입니다 :if (FileImport.HasFile)
{
// Get the name of the Excel spreadsheet to upload.
string strFileName = Server.HtmlEncode(FileImport.FileName);
// Get the extension of the Excel spreadsheet.
string strExtension = Path.GetExtension(strFileName);
// Validate the file extension.
if (strExtension == ".xls" || strExtension == ".xlsx")
{
// Generate the file name to save.
string strUploadFileName = "C:/Documents and Settings/user01/My Documents/Visual Studio 2005/WebSites/MajorProject/UploadFiles/" + DateTime.Now.ToString("yyyyMMddHHmmss") + strExtension;
// Save the Excel spreadsheet on server.
FileImport.SaveAs(strUploadFileName);
// Create Connection to Excel Workbook
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strUploadFileName + ";Extended Properties=Excel 8.0;";
using (OleDbConnection connection =
new OleDbConnection(connStr))
{
string selectStmt = string.Format("Select [COLUMNS] FROM [userlist$]");
OleDbCommand command = new OleDbCommand(selectStmt, connection);
connection.Open();
Console.WriteLine("Connection Opened");
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = "Data Source=<datasource>";
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "UserDB";
bulkCopy.WriteToServer(dr);
return;
}
}
}
전체 데이터베이스 서버가 다운되는 것을 말하고 있습니까? –
@ LasseV.Karlsen 네,'원격 호스트가 원격 호스트에 의해 강제로 닫히고, 서버를 재시작해야 다시 연결될 수 있습니다. – user1084683