| |

VerySource

 Forgot password?
 Register
Search
View: 1987|Reply: 10

Let's work together to solve a difficult problem

[Copy link]

3

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-2 18:40:01
| Show all posts |Read mode
The following code is the code of ado dynamically linking the sql database, but it is not connected, I don't know what the reason is, everyone helps to solve it together. The error is that the exception dialog box is skipped, which says, 'Unable to open the database Book_Data requested during login, login failed'
code show as below:

var
Logintimes: integer = 0;

procedure TEnter_F.FormCreate (Sender: TObject);
var
DLYH_Q: TADOQuery;
ADOCommand: TADOCommand;
  s, DataPath: string;
begin
 Connect: = TADOConnection.Create (nil);
Connect.ConnectionString: = 'Provider = SQLOLEDB; Integrated Security = SSPI; Persist Security Info = False; Initial Catalog = Book_Data';
Connect.LoginPrompt: = false;
try
Connect.Connected: = true;
except
 ADOCommand: = TADOCommand.Create (nil);
ADOCommand.ConnectionString: = 'Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info = False';
DataPath: = ExtractFilePath (Application.ExeName);
s: = 'EXEC sp_attach_db @dbname = N' + char (39) + 'Book_Data' + char (39) + ',' +
'@ filename1 = N' + char (39) + DataPath + 'Book_Data.MDF' + char (39) +
',' + '@ filename2 = N' + char (39) + DataPath + 'Book_Data.LDF' + char (39);
ADOCommand.CommandText: = s;
  ADOCommand.Execute ();
end;

 DLYH_Q: = TADOQuery.Create (nil);
DLYH_Q.Connection: = Connect;
DLYH_Q.SQL.Clear;
DLYH_Q.SQL.Add ('select name from logged in user');
DLYH_Q.Open;
if DLYH_Q.RecordCount> 0 then
while not DLYH_Q.Eof do
begin
XM_CB.Items.Add (DLYH_Q.FieldValues ​​['Name']);
DLYH_Q.Next;
end;
DLYH_Q.Close;
FreeAndNil (DLYH_Q);
  XM_CB.ItemIndex: = 0;
end;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-2 20:30:01
| Show all posts
Forget it for you. .
Reply

Use magic Report

3

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-2 22:18:01
| Show all posts
Why did n’t anyone answer, would n’t it?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-2 22:33:01
| Show all posts
In your Connect.ConnectionString: = 'Provider = SQLOLEDB; Integrated Security = SSPI; Persist Security Info = False; Initial Catalog = Book_Data' ;, no data source is specified, no user ID is specified, no password is specified, how can it be possible on?
Reply

Use magic Report

3

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-2 23:51:02
| Show all posts
How to get the host name dynamically
Reply

Use magic Report

0

Threads

15

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-3 00:36:01
| Show all posts
How to get the host name dynamically
======================================================== ===========================
What does this have to do with your hostname? Either get the database dynamically:

ADOCommand: = TADOCommand.Create (nil);
ADOCommand.ConnectionString: = PromptDataSource (Handle, DataConnection.ConnectionString);
Reply

Use magic Report

3

Threads

7

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-1-3 11:09:01
| Show all posts
Is your above a dynamic link? It doesn't seem to be a connection. It doesn't specify the database name.
Reply

Use magic Report

0

Threads

53

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-1-3 13:51:01
| Show all posts
Database server and database are not specified in ConnectionString
Reply

Use magic Report

0

Threads

15

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-3 20:06:01
| Show all posts
Is your above a dynamic link? It doesn't seem to be a connection. It doesn't specify the database name.
======================================================== ================================
Don't know if you try it
Reply

Use magic Report

0

Threads

15

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-3 20:36:01
| Show all posts
ADOCommand.ConnectionString: = PromptDataSource (Handle, DataConnection.ConnectionString);
To change the above:
ADOCommand.ConnectionString: = PromptDataSource (Handle, ADOCommand.ConnectionString);
or:
ADOCommand.ConnectionString: = PromptDataSource (Handle, ‘’);
Where Handle is the window handle
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list