تحميل ملف ascii إلى قاعدة البيانات
#1
السلام عليكم ورحمة الله،

لم ينجح معي تحميل ملف ASCII إلى قاعدة البيانات SQL Server 2005، سكربت التالي يعطيني رسالة خطأ

كود :
begin qry1.close;{close the query} //asdsign new SQL expression qry1.SQL.Clear; qry1.sql.add ('BULK INSERT ROOM'); qry1.sql.add ('FROM "c:\ASCII.txt"'); qry1.sql.add ('with (fieldterminator = ";", rowterminator = "\n" )'); //qry1.sql.add ('maxerrors = 0'); //qry1.sql.add ('fieldterminator =";"'); //qry1.sql.add ('rowterminator ="\n"'); //qry1.Requestlive := True; qry1.ExecSQL; end;
الرد
#2
وعليكم السلام ورحمة الله وبركاته
كنت استخدم الأداة bcp (مرفقة من SQL Serve) بشيء مثل:
PHP كود :
function ExecuteCmd(CmdLine: string; ShowConsole: Boolean): Boolean;
const
  
flags: array [Boolean] of Integer = (SW_SHOWNORMAL, SW_HIDE);
var
  
cmdBuffer: array [0..MAX_PATH] of Char;
begin
  GetEnvironmentVariable
('COMSPEC', cmdBuffer, SizeOf(cmdBuffer));
  
StrCat(cmdBuffer, ' /C ');
  
StrPCopy(StrEnd(cmdBuffer), CmdLine);
  
Result := ShellExecute(Application.Handle, 'open', 'cmd', cmdBuffer, nil, flags[ShowConsole]) > 32;
end;

procedure BulkCmd(IsExport: Boolean);

  function 
GetValue(ItemName: String): Variant;
  
begin
    Result 
:= DM.Cnt.Properties.Item[ItemName].Value;
  
end;
  function 
PromptFile(var Dir, Title: String; Save: Boolean): Boolean;
  
begin
    Result 
:= BrowseForFile(Dir, 'Data file|*.dat', '*.dat', Title, '.', Save);
  
end;
var
  
sDir, Action, ServerSource, UserName: string;
begin
  ServerSource 
:= 'localhost\sqlexpress';
  
UserName := 'sa';
  
Password := 'P@ssw0rd';
  
TableName := 'YourTable';
  if 
IsExport then begin
    Action 
:= 'Export...';
    if 
not PromptFile(sDir, Action, True) then Exit;
      if 
ExecuteCmd('bcp YourDatabase.dbo.'+TableName+' out "'+sDir+'" -n -S'+ServerSource+' -U'+UserName+' -P'+        Password) then
        
if FileExists(sDir) then
          ShowMessage
('File exported successfully.');
  
end else
    try
      
Action := 'Import...';
      if 
not PromptFile(sDir, Action, False) then Exit;
      
YourDataSet.Close;
      try
        
YourADOConnection.Execute('BULK INSERT '+TableName+' FROM '+QuotedStr(sDir)+' WITH (DATAFILETYPE=''native''); ');
      
except
        ShowMessage
('Cannot import this file!');
      
end;
    finally
      
YourDataSet.Open;
    
end;
end; 
عدلت عليه ليعمل عندك، إذا حصل خلل أعلمني
بالتوفيق.
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...
الرد
#3
مشكور أخي؛ الكود يحتاج إلى تأمل
الرد


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم