我使用ASP.NET和SQL 2008 R2。這種情況意味着我的數據超過了我的表格的極限。但我怎麼能找到/顯示消息給用戶哪個列導致這個問題?被截斷的sql字符串或二進制數據
public static void Put_CSVtoSQL_PerLine(string LeFile)
{
string line = null;
bool IsFirst = true;
string SqlSyntax = Outils.LoadFileToString(Path.Combine(appDir, @"SQL\InsertLV_Temp_Gros.sql"));
int NOID, ENLEV_UNITE, NBR_COLIS, FACTURATION, TRANSPORTEUR, CHAUFFEUR;
DateTime DATE_CLOTURE;
decimal POID,ENLEV_CREMB, ENLEV_DECL;
bool LIVRS_SIGN, LIVRS_SAMD, IS_PRINT, IS_IMPORT;
object CODE_DEST, CODE_CLIENT, MODAL_MODE, LIBELLE_PORT, LIBELLE_EXPR, LIBELLE_UNITE, RS_NOM_EXP;
object ADDR_EXP, CP_EXP, VILLE_EXP, TEL_EXP, FAX_EXP, RS_NOM_DEST, ADDR_DEST, CP_DEST, INSEE_DEST, LE_ZONE, VILLE_DEST, TEL_DEST, FAX_DEST;
object NO_ORDRE_CUMMUL, CODE_MAG, OBS, LIB_AGENCE, LIB_TOURNE;
try
{
using (StreamReader sr = File.OpenText(LeFile))
{
while ((line = sr.ReadLine()) != null)
{
string[] data = line.Split(';');
if (data.Length > 0)
{
if (!IsFirst)
{
string[] data_Innen = data[0].Split(',');
if (data_Innen.Length == 38)
{
NOID = Convert.ToInt32(data_Innen[0].Replace('\'', ' ').Trim());
CODE_DEST = data_Innen[1].Replace('\'', ' ').Trim();
CODE_CLIENT = data_Innen[2].Replace('\'', ' ').Trim();
DATE_CLOTURE = Convert.ToDateTime(data_Innen[3].Replace('\'', ' ').Trim());
MODAL_MODE = data_Innen[4].Replace('\'', ' ').Trim();
LIBELLE_PORT = data_Innen[5].Replace('\'', ' ').Trim();
LIBELLE_EXPR = data_Innen[6].Replace('\'', ' ').Trim();
ENLEV_UNITE = Convert.ToInt32(data_Innen[7].Replace('\'', ' ').Trim());
LIBELLE_UNITE = data_Innen[8].Replace('\'', ' ').Trim();
NBR_COLIS = Convert.ToInt32(data_Innen[9].Replace('\'', ' ').Trim());
POID = Convert.ToDecimal(data_Innen[10].Replace('\'', ' ').Replace('.', ',').Trim());
ENLEV_CREMB = Convert.ToDecimal(data_Innen[11].Replace('\'', ' ').Replace('.', ',').Trim());
ENLEV_DECL = Convert.ToDecimal(data_Innen[12].Replace('\'', ' ').Replace('.', ',').Trim());
RS_NOM_EXP = data_Innen[13].Replace('\'', ' ').Trim();
ADDR_EXP = data_Innen[14].Replace('\'', ' ').Trim();
CP_EXP = data_Innen[15].Replace('\'', ' ').Trim();
VILLE_EXP = data_Innen[16].Replace('\'', ' ').Trim();
TEL_EXP = data_Innen[17].Replace('\'', ' ').Trim();
FAX_EXP = data_Innen[18].Replace('\'', ' ').Trim();
RS_NOM_DEST = data_Innen[19].Replace('\'', ' ').Trim();
ADDR_DEST = data_Innen[20].Replace('\'', ' ').Trim();
CP_DEST = data_Innen[21].Replace('\'', ' ').Trim();
INSEE_DEST = data_Innen[22].Replace('\'', ' ').Trim();
VILLE_DEST = data_Innen[23].Replace('\'', ' ').Trim();
TEL_DEST = data_Innen[24].Replace('\'', ' ').Trim();
FAX_DEST = data_Innen[25].Replace('\'', ' ').Trim();
IS_PRINT = Convert.ToBoolean(data_Innen[26].Replace('\'', ' ').Trim());
IS_IMPORT = Convert.ToBoolean(data_Innen[27].Replace('\'', ' ').Trim());
CHAUFFEUR = Convert.ToInt32(data_Innen[28].Replace('\'', ' ').Trim());
NO_ORDRE_CUMMUL = data_Innen[29].Replace('\'', ' ').Trim();
TRANSPORTEUR = Convert.ToInt32(data_Innen[30].Replace('\'', ' ').Trim());
CODE_MAG = data_Innen[31].Replace('\'', ' ').Trim();
FACTURATION = Convert.ToInt32(data_Innen[32].Replace('\'', ' ').Trim());
LIVRS_SIGN = Convert.ToBoolean(data_Innen[33].Replace('\'', ' ').Trim());
LIVRS_SAMD = Convert.ToBoolean(data_Innen[34].Replace('\'', ' ').Trim());
OBS = data_Innen[35].Replace('\'', ' ').Trim();
LIB_AGENCE = data_Innen[36].Replace('\'', ' ').Trim();
LIB_TOURNE = data_Innen[37].Replace('\'', ' ').Trim();
using (var connectionWrapper = new Connexion())
{
var connectedConnection = connectionWrapper.GetConnected();
SqlCommand comm_Insert = new SqlCommand(SqlSyntax, connectionWrapper.conn);
comm_Insert.Parameters.AddWithValue("@NOID", NOID);
comm_Insert.Parameters.AddWithValue("@CODE_DEST", CODE_DEST);
comm_Insert.Parameters.AddWithValue("@CODE_CLIENT", CODE_CLIENT);
comm_Insert.Parameters.AddWithValue("@DATE_CLOTURE", DATE_CLOTURE);
comm_Insert.Parameters.AddWithValue("@MODAL_MODE", MODAL_MODE);
comm_Insert.Parameters.AddWithValue("@LIBELLE_PORT", LIBELLE_PORT);
comm_Insert.Parameters.AddWithValue("@LIBELLE_EXPR", LIBELLE_EXPR);
comm_Insert.Parameters.AddWithValue("@ENLEV_UNITE", ENLEV_UNITE);
comm_Insert.Parameters.AddWithValue("@LIBELLE_UNITE", LIBELLE_UNITE);
comm_Insert.Parameters.AddWithValue("@NBR_COLIS", NBR_COLIS);
comm_Insert.Parameters.AddWithValue("@POID", POID);
comm_Insert.Parameters.AddWithValue("@ENLEV_CREMB", ENLEV_CREMB);
comm_Insert.Parameters.AddWithValue("@ENLEV_DECL", ENLEV_DECL);
comm_Insert.Parameters.AddWithValue("@RS_NOM_EXP", RS_NOM_EXP);
comm_Insert.Parameters.AddWithValue("@ADDR_EXP", ADDR_EXP);
comm_Insert.Parameters.AddWithValue("@CP_EXP", CP_EXP);
comm_Insert.Parameters.AddWithValue("@VILLE_EXP", VILLE_EXP);
comm_Insert.Parameters.AddWithValue("@TEL_EXP", TEL_EXP);
comm_Insert.Parameters.AddWithValue("@FAX_EXP", FAX_EXP);
comm_Insert.Parameters.AddWithValue("@RS_NOM_DEST", RS_NOM_DEST);
comm_Insert.Parameters.AddWithValue("@ADDR_DEST", ADDR_DEST);
comm_Insert.Parameters.AddWithValue("@CP_DEST", CP_DEST);
comm_Insert.Parameters.AddWithValue("@INSEE_DEST", INSEE_DEST);
comm_Insert.Parameters.AddWithValue("@VILLE_DEST", VILLE_DEST);
comm_Insert.Parameters.AddWithValue("@TEL_DEST", TEL_DEST);
comm_Insert.Parameters.AddWithValue("@FAX_DEST", FAX_DEST);
comm_Insert.Parameters.AddWithValue("@IS_PRINT", IS_PRINT);
comm_Insert.Parameters.AddWithValue("@IS_IMPORT", IS_IMPORT);
comm_Insert.Parameters.AddWithValue("@CHAUFFEUR", CHAUFFEUR);
comm_Insert.Parameters.AddWithValue("@NO_ORDRE_CUMMUL", NO_ORDRE_CUMMUL);
comm_Insert.Parameters.AddWithValue("@TRANSPORTEUR", TRANSPORTEUR);
comm_Insert.Parameters.AddWithValue("@CODE_MAG", CODE_MAG);
comm_Insert.Parameters.AddWithValue("@FACTURATION", FACTURATION);
comm_Insert.Parameters.AddWithValue("@LIVRS_SIGN", LIVRS_SIGN);
comm_Insert.Parameters.AddWithValue("@LIVRS_SAMD", LIVRS_SAMD);
comm_Insert.Parameters.AddWithValue("@OBS", OBS);
comm_Insert.Parameters.AddWithValue("@LIB_AGENCE", LIB_AGENCE);
comm_Insert.Parameters.AddWithValue("@LIB_TOURNE", LIB_TOURNE);
comm_Insert.ExecuteNonQuery();
}
}
}
IsFirst = false;
}
}
}
}
catch (Exception ex)
{
throw new Exception("Err CSV to SQL" + LeFile + "--" + ex.Message, ex);
}
}
在我的catch異常
:
catch (Exception ex)
{
throw new Exception("Err CSV to SQL" + WHICH COLUMN ??? + "--" + ex.Message, ex);
}
不幸的方式SQL Server不會返回那些非常有用的信息。考慮upvoting [新虛擬表:錯誤。它將類似於刪除和插入的表](http://connect.microsoft.com/SQLServer/feedback/details/774754/new-virtual-table-errors-it-would-analogous-to-the-deleted-and插入表)和或[請修復「字符串或二進制數據將被截斷」消息以提供列名稱](https://connect.microsoft.com/SQLServer/feedback/details/339410) –