1

i have c# windows form application which will connect to the ms sql server over internet connection.

i need to connect to it with entity framework to make may day good but , there is a problem with connection. i need to connect with windows authentication

i have connection string like that

Data Source=xxx.xxx.xxx.xxx[SQL INSTANCE];Initial Catalog=mainCatalog;User ID=[userid];Password=[password];

as you know this is SQL Authentication. what can i do to connect to the sql server with connection string which i can describe also windows authentication parameter to let me login.

Thanks.

  • Do you share a domain? eg is it on the same domain you're on or at least trusted? or a completely separate domain? – BugFinder Aug 11 '15 at 13:42
  • completely seperate domain , i have a lot of client about 78 clients. Server manager says please login with windows auth so i had to :(there are a lot of different pc and they all have different domain. – Huzeyfe Coşkun Aug 11 '15 at 13:44
  • If the Sql Server can't contact the domain controller, it can't authenticate the user. – stuartd Aug 11 '15 at 13:45
  • Windows Authentication won't work over Internet. – Rahul Aug 11 '15 at 13:49
  • @stuartd so are there no way to connect? i am asking because i can connect to the server with navicat [windows auth] so i just need to mimic "what they are doing" with c# – Huzeyfe Coşkun Aug 11 '15 at 13:49
  • Are _you_ on the same domain as the Sql Server? – stuartd Aug 11 '15 at 14:19

1 Answers1

0

As others have already commented, you cannot use Windows authentication from the internet. From the internet, your client cannot communicate with your domain controller, which is needed to get the encryption keys used in Windows authentication.

Even if you could, I would advise against exposing your SQL server directly on the internet anyway.

A better option would be to have your Windows Form application talk to a web service and have the web service talk to the SQL server instance. That way, you can put your SQL server behind a firewall and only allow your web service to query it. Your web service can use Windows authentication to talk to SQL Server (if they are installed in the same domain).

Your Windows Forms application can use a token based authentication protocol like OAuth2 to authenticate against your web service.

MvdD
  • 22,082
  • 8
  • 65
  • 93