//导入数据
function TThreadNet.ExecteDataImport: Boolean;
begin
CoInitialize(nil);
Result := False;
try
Dts_SQLConnection := TADOConnection.Create(nil);
Dts_SqlQuery := TADOQuery.Create(nil);
Dts_SQLConnection.Provider := 'SQLOLEDB';
Dts_SQLConnection.ConnectionString := 'Provider=SQLOLEDB.1;User ID='+Trim(Form1.IniSqlLoginName)
+';Password='+Trim(Form1.IniSqlLoginPassword)+';Initial Catalog='
+Trim(Form1.IniSqlDataBase)+';Data Source='+Trim(Form1.IniSqlName);
Dts_SQLConnection.LoginPrompt := False;
Dts_SQLConnection.CommandTimeout := 0;
Dts_SQLConnection.ConnectionTimeout := 0;
Dts_SQLConnection.Open;
try
Form1.AddWorkListItem('连接本地数据服务器','连接成功');
Dts_SqlQuery.Connection := Dts_SQLConnection;
Dts_SqlQuery.CommandTimeout := 0;
Dts_SqlQuery.SQL.Clear;
Dts_SqlQuery.SQL.Add('Exec DataInTrans :InPath');
Dts_SqlQuery.Parameters.ParamByName('InPath').Value := Form1.IniSqlInDir+'\';
Form1.NetServerInfo.Strings[2] := '正在导入数据';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行导入数据','请稍候...');
Dts_SqlQuery.ExecSQL;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.DownFileList.RefreshItems;
if Form1.DownFileList.Items.Count <> 0 then
begin
Form1.AddWorkListItem('校验数据是否导入成功','数据未完全导入,请与管理员联系');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Exit;
end;
Form1.NetServerInfo.Strings[2] := '导入数据成功';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导入','导入成功');
Result := True;
except
on E:Exception do
begin
Application.MessageBox(PChar(E.Message),'Error');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('执行数据导入','执行错误,请与管理员联系');
Exit;
end;
end;
except
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('连接本地数据服务器','连接失败,请与管理员联系');
Exit;
end;
CoUninitialize;
end;//导出数据
function TThreadNet.ExecteDataExprot: Boolean;
begin
CoInitialize(nil);
Result := False;
try
Dts_SQLConnection := TADOConnection.Create(nil);
Dts_SqlQuery := TADOQuery.Create(nil);
Dts_SQLConnection.Provider := 'SQLOLEDB';
Dts_SQLConnection.ConnectionString := 'Provider=SQLOLEDB.1;User ID='+Trim(Form1.IniSqlLoginName)
+';Password='+Trim(Form1.IniSqlLoginPassword)+';Initial Catalog='
+Trim(Form1.IniSqlDataBase)+';Data Source='+Trim(Form1.IniSqlName);
Dts_SQLConnection.LoginPrompt := False;
Dts_SQLConnection.CommandTimeout := 0;
Dts_SQLConnection.ConnectionTimeout := 0;
Dts_SqlQuery.Connection := Dts_SQLConnection;
Dts_SqlQuery.CommandTimeout := 0;
Dts_SQLConnection.Open;
try
Form1.AddWorkListItem('连接本地数据服务器','连接成功');
Dts_SqlQuery.SQL.Clear;
Dts_SqlQuery.SQL.Add('Exec DataOutTrans :OutPath,:Storeid');
Dts_SqlQuery.Parameters.ParamByName('OutPath').Value := Form1.IniSqlOutDir+'\';
Dts_SqlQuery.Parameters.ParamByName('Storeid').Value := Form1.NetServerInfo.Strings[0];
Form1.NetServerInfo.Strings[2] := '正在生成数据文件';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导出','请稍候...');
Dts_SqlQuery.ExecSQL;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.OutFileList.RefreshItems;
if Form1.OutFileList.Items.Count <> Form1.IniSqlOutFileCount then
begin
Form1.AddWorkListItem('校验数据导出是否完整','数据导出不完整,请与管理员联系');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Exit;
end;
Form1.NetServerInfo.Strings[2] := '生成数据文件成功';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导出','导出成功');
Result := True;
Exit;
except
on E:Exception do
begin
Application.MessageBox(PChar(E.Message),'Error');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('执行数据导出','执行错误,请与管理员联系');
Exit;
end;
end;
except
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('连接本地数据服务器','连接失败,请与管理员联系');
Exit;
end;
CoUninitialize;
end;
上面是一段线程中的代码,在数据导出模块中有时会产生“NO Connect”错误,通过调式发现问题出在TADOQuery上,奇怪的是Dts_SQLConnection的Connected状态是True,查了很久都没搞清楚真正的原因在哪里,请各位高手指点下。
function TThreadNet.ExecteDataImport: Boolean;
begin
CoInitialize(nil);
Result := False;
try
Dts_SQLConnection := TADOConnection.Create(nil);
Dts_SqlQuery := TADOQuery.Create(nil);
Dts_SQLConnection.Provider := 'SQLOLEDB';
Dts_SQLConnection.ConnectionString := 'Provider=SQLOLEDB.1;User ID='+Trim(Form1.IniSqlLoginName)
+';Password='+Trim(Form1.IniSqlLoginPassword)+';Initial Catalog='
+Trim(Form1.IniSqlDataBase)+';Data Source='+Trim(Form1.IniSqlName);
Dts_SQLConnection.LoginPrompt := False;
Dts_SQLConnection.CommandTimeout := 0;
Dts_SQLConnection.ConnectionTimeout := 0;
Dts_SQLConnection.Open;
try
Form1.AddWorkListItem('连接本地数据服务器','连接成功');
Dts_SqlQuery.Connection := Dts_SQLConnection;
Dts_SqlQuery.CommandTimeout := 0;
Dts_SqlQuery.SQL.Clear;
Dts_SqlQuery.SQL.Add('Exec DataInTrans :InPath');
Dts_SqlQuery.Parameters.ParamByName('InPath').Value := Form1.IniSqlInDir+'\';
Form1.NetServerInfo.Strings[2] := '正在导入数据';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行导入数据','请稍候...');
Dts_SqlQuery.ExecSQL;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.DownFileList.RefreshItems;
if Form1.DownFileList.Items.Count <> 0 then
begin
Form1.AddWorkListItem('校验数据是否导入成功','数据未完全导入,请与管理员联系');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Exit;
end;
Form1.NetServerInfo.Strings[2] := '导入数据成功';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导入','导入成功');
Result := True;
except
on E:Exception do
begin
Application.MessageBox(PChar(E.Message),'Error');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('执行数据导入','执行错误,请与管理员联系');
Exit;
end;
end;
except
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('连接本地数据服务器','连接失败,请与管理员联系');
Exit;
end;
CoUninitialize;
end;//导出数据
function TThreadNet.ExecteDataExprot: Boolean;
begin
CoInitialize(nil);
Result := False;
try
Dts_SQLConnection := TADOConnection.Create(nil);
Dts_SqlQuery := TADOQuery.Create(nil);
Dts_SQLConnection.Provider := 'SQLOLEDB';
Dts_SQLConnection.ConnectionString := 'Provider=SQLOLEDB.1;User ID='+Trim(Form1.IniSqlLoginName)
+';Password='+Trim(Form1.IniSqlLoginPassword)+';Initial Catalog='
+Trim(Form1.IniSqlDataBase)+';Data Source='+Trim(Form1.IniSqlName);
Dts_SQLConnection.LoginPrompt := False;
Dts_SQLConnection.CommandTimeout := 0;
Dts_SQLConnection.ConnectionTimeout := 0;
Dts_SqlQuery.Connection := Dts_SQLConnection;
Dts_SqlQuery.CommandTimeout := 0;
Dts_SQLConnection.Open;
try
Form1.AddWorkListItem('连接本地数据服务器','连接成功');
Dts_SqlQuery.SQL.Clear;
Dts_SqlQuery.SQL.Add('Exec DataOutTrans :OutPath,:Storeid');
Dts_SqlQuery.Parameters.ParamByName('OutPath').Value := Form1.IniSqlOutDir+'\';
Dts_SqlQuery.Parameters.ParamByName('Storeid').Value := Form1.NetServerInfo.Strings[0];
Form1.NetServerInfo.Strings[2] := '正在生成数据文件';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导出','请稍候...');
Dts_SqlQuery.ExecSQL;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.OutFileList.RefreshItems;
if Form1.OutFileList.Items.Count <> Form1.IniSqlOutFileCount then
begin
Form1.AddWorkListItem('校验数据导出是否完整','数据导出不完整,请与管理员联系');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Exit;
end;
Form1.NetServerInfo.Strings[2] := '生成数据文件成功';
Form1.TcpServer.Socket.Write(Form1.NetServerInfo,True);
Form1.AddWorkListItem('执行数据导出','导出成功');
Result := True;
Exit;
except
on E:Exception do
begin
Application.MessageBox(PChar(E.Message),'Error');
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SqlQuery.Close;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('执行数据导出','执行错误,请与管理员联系');
Exit;
end;
end;
except
if Form1.TCPServer.Connected then Form1.TCPServer.Disconnect;
if Form1.FTPConnect.Connected then Form1.FTPConnect.Disconnect;
Dts_SQLConnection.Close;
Form1.AddWorkListItem('连接本地数据服务器','连接失败,请与管理员联系');
Exit;
end;
CoUninitialize;
end;
上面是一段线程中的代码,在数据导出模块中有时会产生“NO Connect”错误,通过调式发现问题出在TADOQuery上,奇怪的是Dts_SQLConnection的Connected状态是True,查了很久都没搞清楚真正的原因在哪里,请各位高手指点下。
解决方案 »
- 如何让DBGrid的cell的底色不同?
- 请问在delphi中能引用olb文件吗?如何引用?
- 本人准备了1000分,解决关于网络传输问题,希望高手们给予解答,谢谢!UP有分啊!!!!!!
- 想用showmessage显示一句比较长的话,需要换行,应该怎么写?
- 用FastReport可不可以做这样的报表?
- D2010设置问题,会的来一下帮忙
- 不知道各位朋友有否delphi6 中采用websnap开发聊天室的经验?
- 请问Delphi中是否有删除字符串前后空格的函数?
- 如何获得本机安装的WINDOWS 版本 和该机的物理内存?
- Delphi的查询问题,分不够可再加,快进来拿分!!!!!!!!!!!!!!
- 如何模拟向其他程界面发送鼠标滚动作
- delphi2007中关于shockwaveflash的安装问题
Dts_SQLConnection.CommandTimeout := 0;//设置为0,太夸张了吧?
Dts_SQLConnection.ConnectionTimeout := 0;//设置为0,太夸张了吧?
因为你没有提供足够的时间让他来处理连接问题。