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:
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.xxxI 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:
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?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:
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?
There is no way to convert your code-first classes into database-first classes. Creating the model from the database will create a whole new set of classes, regardless of the presence of your code-first classes. However, you might not want to delete your code-first classes right away.
The main difference between Code First approach and Database First approach is that the Code First enables you to write entity classes and its properties first without creating the database design first.
Remove Integrated Security=True
from your connection string as you're trying to connect with a SQL Server username/password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With