Question

I am working on a local machine (ASP.NET MVC 4 application) but now I want to start using the company's SQL server so I need to change the Connection string in order to connect me to that remote server.

The set up is this:

  • I have a VPN connection where I use an IP address, can't show the exact IP so let's say - xxx.xxx.xxx.xxx
  • I have username and password in order to connect to VPN - VPNUsername/VPNPassword
  • When I use Microsoft SQL Server Management Studio to connect to the remote server I use the same IP that I use to connect to the VPN - xxx.xxx.xxx.xxx
  • I have different username and password for the SQL Server - SQLUsername/SQLPassword

I have an existing connection string that I use to connect to the server on my PC so I thought it would be enough to just change the parameters there like so :

<add name="ProjectName.DAL.MyDbContext"
     providerName="System.Data.SqlClient"
     connectionString="Data Source=xxx.xxx.xxx.xxx;
     Initial Catalog=DatabaseName;Integrated Security=True;         
     MultipleActiveResultSets=True;
     user id=SQLUsername;password=SQLPassword;App=EntityFramework" />

So the changes from the connection string that works and connects me to my local server are two:

  1. Data Source= xxx.xxx.xxx.xxx - I'm using the IP. Here I wonder if the IP itself is sufficinet. Should I use http://xxx.xxx.xxx.xxx or just IP is ok?
  2. user id=SQLUsername;pasword=SQLPassword - I'm using the same Username and Password as in the Management studio from where I can connect successfully to the remove server by providing the xxx.xxx.xxx.xxx as Server name and using SQLUsername/SQLPassword under SQL Server Authentincation.

So to be clear - under Management Studio I have no problems connecting to the remote server. However, when I change the connection string to what I posted above in my HomeController where I have very simple logic just to check that the call to the database is executed :

private MyDbContext db = new MyDbContext();

        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View(db.Users.ToList());
        }

I get 3 exceptions:

  1. SqlException (0x80131904): Login failed for user 'VPNUsername'
  2. ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.
  3. ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.

So besides that in my opinion and as the number 3 exception tells that the problem is in the way I'm using the connection string what concerns me is also the Number 1 exception that says that login is failed but not for my SQLUsername but for the VPNUsername. As I said - I'm really using VPN connection and I use the same IP - xxx.xxx.xxx.xxx to connect both to the VPN and the SQL Server(From Management Studio).

Any idea how to resolve this?

Was it helpful?

Solution

Remove Integrated Security=True from your connection string as you're trying to connect with a SQL Server username/password

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top