Advertisement
Advertisement
| 07.23.2008 at 10:33AM PDT, ID: 23589418 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: |
procedure TForm1.Button1Click(Sender: TObject);
var i : Integer;
begin
Memo1.Clear;
qry.Close;
ADOConn1.DefaultDatabase := '';
ADOConn1.Connected := True;
qry.Connection := ADOConn1;
qry.SQL.Clear;
qry.SQL.Add('Exec SP_DATABASES');
try
qry.Active := True;
while not qry.Eof do
begin
CheckDBName( qry.FieldByName('DATABASE_NAME').AsString );
qry.Next;
end;
qry.Close;
except
on e : exception do begin
ShowMessage('Error getting Databases:' + e.Message);
end;
end
end;
function TForm1.CheckDBName(aName : String): Boolean;
begin
Result := True;
try
if chkUseWorkAround.Checked then
ChangeDefaultDB(ADOConn2, aName) //<< This is my work-around
else
ADOConn2.DefaultDatabase := aName; // << This will throw an exception
Memo1.Lines.Add(Format('Good: %s %s', [ADOConn2.DefaultDatabase, aName]));
qry2.Close;
qry2.SQL.Clear;
qry2.SQL.Add('EXEC SP_TABLES @table_owner = ''dbo''');
qry2.Active := True;
Result := (not qry2.Eof);
qry2.Active := False;
except
on e : exception do begin
Memo1.Lines.Add(Format('Bad: %s %s', [ADOConn2.DefaultDatabase, aName]));
Memo1.Lines.Add(' Error:' + e.Message);
result := false;
end;
end;
end;
function TForm1.ChangeDefaultDB(aADOConnection : TADOConnection ; aNewDBName : string) : Boolean;
var s1, s2: string;
p : integer;
SaveConnected : Boolean;
begin
// Remove Initial Catalog from connection string and
// replace it with new Database name.
// Unfortunatly we have to disconnect to do this.
SaveConnected := aADOConnection.Connected;
aADOConnection.Connected := False;
s1 := aADOConnection.ConnectionString;
p := pos('Initial Catalog=',s1);
if (p <> 0) and (length(s1) > p + 16) then
begin
s1 := copy(s1,1 ,p -1);
s2 := copy(aADOConnection.ConnectionString,p,length(aADOConnection.ConnectionString));
p := pos(';',s2);
if p = 0 then
aADOConnection.ConnectionString := s1 + ';Initial Catalog=' + aNewDBName
else begin
aADOConnection.ConnectionString := s1 + copy(s2,p +1,length(s2)) + ';Initial Catalog=' + aNewDBName;
end;
end
else
aADOConnection.ConnectionString := aADOConnection.ConnectionString + ';Initial Catalog=' + aNewDBName;
Result := True;
try
aADOConnection.Connected := SaveConnected;
except
Result := False;
end;
end;
|