I am following https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db to learn how to use the new .Net Core and Entity Framework Core and I am trying to create the connection string to a remote SQL Server. I updated the server and database strings but it does not show how to specify the username and password. I have done some digging but every entity framework core example I find is for localDB only. How am I to properly specify the login credentials and what should Trusted_Connection be set to for a remote SQL Server 2016 server?
-
You can replace user id and password for connection string in DbContext with dependency injection, have you tried that ?H. Herzl– H. Herzl2016-12-26 01:55:07 +00:00Commented Dec 26, 2016 at 1:55
-
@H.Herzl Huh? I am asking how to specify it in the base connection string.Matthew Verstraete– Matthew Verstraete2016-12-26 01:56:37 +00:00Commented Dec 26, 2016 at 1:56
-
1Google is your friend... connectionstrings.com/sql-serverTseng– Tseng2016-12-26 02:48:33 +00:00Commented Dec 26, 2016 at 2:48
-
It's the same connection string, e.g.: server=(local);database=Foo;user id=name;password=123;H. Herzl– H. Herzl2016-12-26 03:05:14 +00:00Commented Dec 26, 2016 at 3:05
-
@Tseng I was googleing just never found that page. Thanks for the link. If you want to use the first "standard security" and link to the page as an answer I will mark it as so.Matthew Verstraete– Matthew Verstraete2016-12-26 03:11:56 +00:00Commented Dec 26, 2016 at 3:11
Add a comment
|
2 Answers
The connection strings in EF Core remain the same as in EF6 and when you use pure ADO.NET.
For user/password authentication it's Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;.
For a list of common connection strings for SQL Server (and others), look at https://www.connectionstrings.com/sql-server/.
Comments
There is small difference in the connection string for the core.You can find it in the MSDN Blog.
we need to specify the server port number in the connection string.
Server = tcp:<ServerName>,<PortName>; Database = <DataBaseName>; User Id = <UserName>; Password = <Password>;
To get the server port number using the following query.
select distinct local_net_address, local_tcp_port from sys.dm_exec_connections where local_net_address is not null