Recent

Author Topic: MS sql connect with win login username and password  (Read 2318 times)

SteenJorgensen

  • Jr. Member
  • **
  • Posts: 68
MS sql connect with win login username and password
« on: February 26, 2019, 09:10:41 am »
I want to connect to my mssql server using the windows login.
 
For now i have a code that read all data to the connections component from a ini file like this:
Code: Pascal  [Select][+][-]
  1. SQLDBLibraryLoader1.Enabled   := True;
  2. MSSQLConnection1.HostName     := INI.ReadString('DB', 'Host', '');
  3. MSSQLConnection1.DatabaseName := INI.ReadString('DB', 'Databasename', '');
  4. MSSQLConnection1.UserName := INI.ReadString('DB', 'Database user name', '') ; //Need win user
  5. MSSQLConnection1.Password := INI.ReadString('DB', 'Database password', '') ;    //Need win password    
  6.  

This works fine BUT i want to use the windows login username and password.

Do any have a solutions for this?


----------------------------------------
Lazarus version 2.0.12 64-bit
FPC 3.2.0

rvk

  • Hero Member
  • *****
  • Posts: 6171
Re: MS sql connect with win login username and password
« Reply #1 on: February 26, 2019, 09:54:13 am »
Do you want to connect to the MSSQL server with your own Windows credentials?
In that case you should just set Username and Password to empty.
You can see and test that with the example in lazarus/examples/mssql.
It has a checkbox in the loginform for OSAuthentication.

If you want to use a different user then you'll need to impersonate that user.
I haven't seen it done in Lazarus but you can check out some Delphi code here:
https://stackoverflow.com/a/1847035/1037511

SteenJorgensen

  • Jr. Member
  • **
  • Posts: 68
Re: MS sql connect with win login username and password
« Reply #2 on: February 26, 2019, 11:56:45 am »
Thanks. This help. Now this works.
----------------------------------------
Lazarus version 2.0.12 64-bit
FPC 3.2.0

 

TinyPortal © 2005-2018