sqldependency work fine locally but fail remotly !

Hmidi Amine 61 Reputation points
2022-03-26T18:02:57.657+00:00

Hi,

I have a c# app that work fine on local machine, i'm using SqlDependency notifications.

Now i configured my sql server to accept remote connexion from the internet and everything is ok, i can connect to my database from management studio through internet :
server name : public ip address : x.x.x.x
user : sa
password : ****

In my c# app i'm using this string connexion :
Data Source=x.x.x.x;Initial Catalog=database_name;Persist Security Info=True;User ID=sa;Password=****

Now when i'm try to run my app remotly i'm facing this error : Login failed for user 'sa', the error occur on 5th line (when trying to start SqlDependency service):

        SqlConnection dependencyCnx;
        SqlCommand sqlCommand;
        dependencyCnx = new SqlConnection(myStringCnx);
        dependencyCnx.Open();
        SqlDependency.Start(dependencyCnx.ConnectionString);

I'm not professionnal on c# and sql server, so what i must to do to avoid this problem ?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
11,608 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,479 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 93,056 Reputation points
    2022-03-26T18:21:57.14+00:00

    Now i configured my sql server to accept remote connexion from the internet and everything is ok, i can connect to my database from management studio through internet :

    Remove the instance from Internet immediately! And never have a blank password for sa! As a matter of fact, I would recommend that you uninstall SQL Server and take your computer to the cleaners. It is very likely that it has been infected already.

    As for why you get that error message, the answer is probably that you are connecting to a difference instance that you think you are connecting to, and at least this instance has a password for sa. But that is your smallest problem right now.

    I very strongly recommend you not to expose SQL Server on the Internet!

    0 comments No comments

  2. Hmidi Amine 61 Reputation points
    2022-03-26T18:31:30.62+00:00

    thank you for your quick response

    but if i want to make my app remotly connected what i must to do ? a VPN for example to avoid this risk or what you propose for me ?

    Cordially


  3. Hmidi Amine 61 Reputation points
    2022-03-27T16:19:57.327+00:00

    Any body have idea how to configure VPN to do that job ? and what type of VPN to choose ? is Nord VPN can do the job ?
    Thank you.