问题
At our workplace, we have an ASP.NET application that uses Microsoft SQL Server 2016 Web Edition Database Server for the back-end database.
At first, In the ASP.NET application web.config, I configured the Database Connection String to be:
Password=blahPasswordblah;
Persist Security Info=True;
User ID=sa;
Initial Catalog=yadaDatabaseNameyada;
Data Source=blahDNSServerNameblah\yadaSQLServerInstanceNameyada
It seemed to connect properly. However, I noticed something strange when the code in the ASP.NET application would try to query a particular view. The query would return an empty result set.
However, when I changed the connection string to include the workstation id and the application name:
Password=blahPasswordblah;
Persist Security Info=True;
User ID=sa;
Initial Catalog=yadaDatabaseNameyada;
Data Source=blahDNSServerNameblah\yadaSQLServerInstanceNameyada;
workstation id=blahWorkStationIDblah;
application name=blahApplicationNameBlah
the query on the view in question would return the proper data that I expected.
Here is the metadata about the view:
USE yadaDatabaseNameyada;
SELECT *
FROM INFORMATION_SCHEMA.VIEWS
WHERE table_name = 'blahViewOfInterestblah'
TABLE_CATALOG
yadaDatabaseNameyada
TABLE_SCHEMA
dbo
TABLE_NAME
blahViewOfInterestblah
VIEW_DEFINITION
Create View dbo.blahViewOfInterestblah ..........
CHECK_OPTION
NONE
IS_UPDATABLE
NO
Why does the query on the view in question return the actual proper results when I include the workstation id and the application name in the Database Connection String?
The reason why I’m asking is because when we ultimately deploy the ASP.NET application to production, it would be poor practice to have a “workstation id” attribute and the "application name" attribute in the Database Connection String.
Why won't it work withOut the “workstation id” attribute and the "application name" attribute?
回答1:
Though this is an old question, I was looking for info on this very subject, so as a partial answer to this question, and without knowing more about the configuration of the database, server and application user account, here's my brief answer:
According to Microsoft, both Application (APP) and Workstation ID (WSID) are optional:
APP Name of the application calling SQLDriverConnect (optional). If specified, this value is stored in the master.dbo.sysprocesses column program_name and is returned by sp_who and the APP_NAME functions.
WSID The workstation ID. Typically, this is the network name of the computer on which the application resides (optional). If specified, this value is stored in the master.dbo.sysprocesses column hostname and is returned by sp_who and the APP_NAME and the HOST_NAME function.
Have you tried changing the privileges of the application SQL user or adding them to the DBO role?
来源:https://stackoverflow.com/questions/45572848/why-do-i-have-to-include-the-workstation-id-and-application-name-attributes