Windows Service SQL Server Error - "Login failed for user"

I have a Windows service written in C # running on a Windows Server 2012 R2 machine that connects to a remote instance of SQL Server 2012 also on a Windows Server 2012 R2 server.

The SQL connection string is defined in App Config as follows:

<connectionStrings>
    <add name="destinationConnectionString" providerName="System.Data.SqlClient"
    connectionString="Server=10.42.42.10;Database=mydb;User ID=myuser;Password=mypass" />
</connectionStrings>

When the service starts, the output error log displays:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'MyUser'.

Error Number: 18456, Condition: 1, Class: 14

So, I check the SQL Server logs to find out more error information and find this

Login failed for user myuser Cause: Password does not match login "

Source: Message: Error: 18456, Severity: 14, State: 8.

, , . .

, SQL Server Management Studio SQL Server , " SQL Server".

, SSMS, Windows. , SSMS. Windows?

, - , ?

: , :

sqlcmd -S 10.42.42.10 -U myuser -P mypass -d mydb
+4
6

:

Server = 10.42.42.10; = mydb; = myuser; = mypass

, " " , , (, , ?) . , " " .

, , . . :

Server = 10.42.42.10; = mydb; = "myuser"; = "mypass"

, .

, , XML. , :

< with &lt;
> with &gt;
& with &amp;
' with &apos;
" with &quot;

, , .

. , , . , :

string connStr = ConfigurationSettings.AppSettings("myConnectionString");

connStr . , .

+3

, XML. , escape- .

, PASS<WORD, : PASS&lt;WORD

+1

,

: Server = myServerAddress; Database = myDataBase; User Id = myUsername; Password = MyPassword;

sql? Server = 10.42.42.10/SomeInstance

+1

; . , .

: ?

+1

, Windows, SQL. , , Windows . . Windows MYDOMAIN\sa P@ssword, SQL Server sa P@ssw0rd.

, , SQL- , "" node , .

+1

, :

, SQL- Server Server=localhost Server=localhost\SQLEXPRESS, !:)

0

Source: https://habr.com/ru/post/1613270/


All Articles