I have a connection开发者_如何学Python string (SQL Server):
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
My goal is to send inside the connection string the "pc name".
This is so I can later Audit it, or to later see the information in log file from which computer the user has been connected to the SQL Server.
You can have Workstation ID
in the connection string. Whatever you put in there is shown in SQL Server Profiler in column HostName
.
In my testing I found that if you do not specify Workstation ID
in the connection string you will still get the the name of the client computer automatically.
Data Source=myServerAddress;Initial Catalog=myDataBase;
User Id=myUsername;Password=myPassword;Application Name=yourpcname
If "yourpcname" is the name of your PC. In SQL profiler or login audit - capture the Application Name for a specific SQL user ID.
Note: It is recommended to use Windows authentication whenever possible.
精彩评论