myHandle:=LoadLibrary('DBConn.dll'); //載入DLL
@SQLConnLib:=GetProcAddress(myHandle,'CreateSQLServerConn');//獲取到DLL中的函式
sqlconnection:=SQLConnLib('.','master','','');
QueryData:=sqlconnection.DoQuery('select * from sys.databases');
//連接access資料庫獲取特征表
@accessConnLib:=GetProcAddress(myHandle,'CreateAccessConn');//獲取到DLL中的函式
accconn:=accessConnLib('fpconfig.dat','FPSearchInfor');
if not accconn.GetConnectState then
begin
ShowMessage('軟體資料資訊讀取失敗,請檢查access資料資料庫!');
end;
accquery:= accconn.DoQuery('select FPTableString from FPSearchInfor ');
while not accquery.Eof do
begin
str:=accquery.FieldByName('FPTableString').AsString;
ShowMessage(str);
while not (QueryData.Eof) do
begin
// ShowMessage(VarToStr(QueryData.Recordset.Fields['name'].Value));
// flag:=true;
// sqlconn:=SQLConnLib('.','UFDATA_666_2014','','');
sqlconn:=SQLConnLib('.',''+QueryData.Recordset.Fields['name'].Value+'','','');
j:=1;
table:=True;
//str:=accquery.FieldByName('FPTableString').AsString;
//查詢dat檔案中一串列是否存在多個表名
if(pos('|',str)=0)then
begin
//ShowMessage('select name from sysobjects where name in ('''+accquery.Recordset.Fields['FPTableString'].Value+''')');
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in ('''+str+''')');
//showmessage(sqlquery.Recordset.Fields['name'].Value);
//查詢資料庫中是否存在特征表
if sqlquery.RecordCount>0 then
begin
showmessage(QueryData.Recordset.Fields['name'].Value+' is u8');
end
else if sqlquery.RecordCount=0 then
begin
table:=false;
end;
sqlquery.Next;
end;
//QueryData.Next;
while (pos ('|',str)>0) and ( table = true ) do
begin
i:=pos('|',str);
FPstr:=Copy(str,1,i-1);
ShowMessage('select name from sysobjects where name in('''+FPstr+''')');
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
//showmessage(sqlquery.Recordset.Fields['name'].Value);
if(sqlquery.RecordCount = 0) then
//showmessage(QueryData.Recordset.Fields['name'].Value);
begin
table:=False;
continue;
end;
if(sqlquery.RecordCount > 0) then
begin
Delete(str,1,i);
//ShowMessage(str);
FPstr:=str;
if(pos('|',str)=0)then
begin
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
if(sqlquery.RecordCount = 0) then
//showmessage(QueryData.Recordset.Fields['name'].Value);
begin
table:=False;
continue;
end;
//sqlquery.Close;
// sqlquery.ClearFields;
// sqlquery.Open;
end;
sqlquery.Next;
end;
//若為true,則該資料庫包含這一列的資料庫表
//inc(j);
end;
if (table=true )then
begin
showmessage(QueryData.Recordset.Fields['name'].Value+'is u8');
end;
QueryData.Next;
//ShowMessage(QueryData.Recordset.Fields['name'].Value);
end;
accquery.Next;
end;
access violation at address 00402256 in module
uj5u.com熱心網友回復:
資料庫多次連接之后會報錯,不知是否連接過多導致問題,跪求各位大神籠罩
uj5u.com熱心網友回復:
困擾多天的一大問題,請求大神現身!!!!!!!
uj5u.com熱心網友回復:
myHandle:=LoadLibrary('DBConn.dll'); //載入DLL
@SQLConnLib:=GetProcAddress(myHandle,'CreateSQLServerConn');//獲取到DLL中的函式
sqlconnection:=SQLConnLib('.','master','','');
QueryData:=sqlconnection.DoQuery('select * from sys.databases');
//連接access資料庫獲取特征表
@accessConnLib:=GetProcAddress(myHandle,'CreateAccessConn');//獲取到DLL中的函式
accconn:=accessConnLib('fpconfig.dat','FPSearchInfor');
if not accconn.GetConnectState then
begin
ShowMessage('軟體資料資訊讀取失敗,請檢查access資料資料庫!');
end;
accquery:= accconn.DoQuery('select FPTableString from FPSearchInfor ');
while not accquery.Eof do
begin
str:=accquery.FieldByName('FPTableString').AsString;
ShowMessage(str);
while not (QueryData.Eof) do
begin
// ShowMessage(VarToStr(QueryData.Recordset.Fields['name'].Value));
// flag:=true;
// sqlconn:=SQLConnLib('.','UFDATA_666_2014','','');
sqlconn:=SQLConnLib('.',''+QueryData.Recordset.Fields['name'].Value+'','','');
j:=1;
table:=True;
//str:=accquery.FieldByName('FPTableString').AsString;
//查詢dat檔案中一串列是否存在多個表名
if(pos('|',str)=0)then
begin
//ShowMessage('select name from sysobjects where name in ('''+accquery.Recordset.Fields['FPTableString'].Value+''')');
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in ('''+str+''')');
//showmessage(sqlquery.Recordset.Fields['name'].Value);
//查詢資料庫中是否存在特征表
if sqlquery.RecordCount>0 then
begin
showmessage(QueryData.Recordset.Fields['name'].Value+' is u8');
end
else if sqlquery.RecordCount=0 then
begin
table:=false;
end;
sqlquery.Next;
end;
//QueryData.Next;
while (pos ('|',str)>0) and ( table = true ) do
begin
i:=pos('|',str);
FPstr:=Copy(str,1,i-1);
ShowMessage('select name from sysobjects where name in('''+FPstr+''')');
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
//showmessage(sqlquery.Recordset.Fields['name'].Value);
if(sqlquery.RecordCount = 0) then
//showmessage(QueryData.Recordset.Fields['name'].Value);
begin
table:=False;
continue;
end;
if(sqlquery.RecordCount > 0) then
begin
Delete(str,1,i);
//ShowMessage(str);
FPstr:=str;
if(pos('|',str)=0)then
begin
sqlquery:=sqlconn.DoQuery('select name from sysobjects where name in('''+FPstr+''')');
if(sqlquery.RecordCount = 0) then
//showmessage(QueryData.Recordset.Fields['name'].Value);
begin
table:=False;
continue;
end;
//sqlquery.Close;
// sqlquery.ClearFields;
// sqlquery.Open;
end;
sqlquery.Next;
end;
//若為true,則該資料庫包含這一列的資料庫表
//inc(j);
end;
if (table=true )then
begin
showmessage(QueryData.Recordset.Fields['name'].Value+'is u8');
end;
QueryData.Next;
//ShowMessage(QueryData.Recordset.Fields['name'].Value);
end;
accquery.Next;
end;
end;
uj5u.com熱心網友回復:
沒仔細看,Delphi資料庫只需要連接一次即可使用,除非是網路例外或其他問題導致連接失敗時,需要重新連接。 如果資料庫連接資訊時封裝在dll中的話,只需呼叫一次就行了,重復呼叫時,需要及時釋放myHandle資源。uj5u.com熱心網友回復:
soga,連接不同的資料庫是不是也要把資源釋放,不然會導致????
uj5u.com熱心網友回復:
如果所有資料庫連接資訊都封裝在DLL內,只需釋放myHandle就可以,如果是多個DLL,需要釋放多個myHandle資源。uj5u.com熱心網友回復:
這代碼以后維護要喊爹了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/81152.html
標籤:數據庫相關
