Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying login creditials for remote SQL connection string in ASP.Net/Entity Framework Core

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?

like image 892
Matthew Verstraete Avatar asked Dec 26 '16 01:12

Matthew Verstraete


People also ask

How do I pass username and password in SQL connection string?

Using a non-standard port Server=myServerName,myPortNumber;Database=myDataBase;User Id=myUsername;Password=myPassword; The default SQL Server port is 1433 and there is no need to specify that in the connection string.

Where do I put connection string in asp net core?

The connection string should be added to your application's App. config file (Web. config if you are using ASP.NET). If your connection string contains sensitive information, such as username and password, you can protect the contents of the configuration file using Protected Configuration.

How do I change the connection string in Entity Framework?

If you want to change the connection string go to the app. config and remove all the connection strings. Now go to the edmx, right click on the designer surface, select Update model from database, choose the connection string from the dropdown, Click next, Add or Refresh (select what you want) and finish.

Where does net core store connection string?

ASP.NET Core Connection String is mainly used to connect to the database, which can be stored in the appsetting. json.


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/.

like image 137
Tseng Avatar answered Oct 11 '22 22:10

Tseng


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
like image 25
Sathish Avatar answered Oct 12 '22 00:10

Sathish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!