Click here to Skip to main content
15,891,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im Setting DB for SQL Server & having 2 more systems & connection via LAN so
SQL installed in one system ?let me know how to connect DB for another system

What I have tried:

**Connecting DB fine and working below code for Computer1
C#
public void ConfigureServices(IServiceCollection services)
{
   services.AddEntityFrameworkSqlServer().AddDbContext<catalogdbcontext> 
  (Option=>Option.UseSqlServer(@"Data Source=MACHINE-2;Initial 
  Catalog=ShoppingCart;Integrated Security=True;Pooling=False"));      
}
**Not Connecting for DB with Computer2 :
public void Configure Services(IServiceCollection services)
{
   services.AddEntityFrameworkSqlServer().AddDbContext<catalogdbcontext> 
   (Option=>Option.UseSqlServer(@"Data Source=192.168.2.2;Initial 
    Catalog=ShoppingCart;Integrated Security=True;Pooling=False"));      
}
Posted
Updated 31-Jan-19 2:45am
v2

In your connection strings, you're using "Integrate Security=true". Do you know what that means?

That means whatever account is running your code is the account that is used to attempt to login to SQL Server. If that account doesn't have permissions to login to the server, the login is going to fail.

So, it appears that the user running on the first workstation does have permissions to the server and database and the user on the second machine does not.

The only time using Trusted Connection makes sense is when you're in a domain environment (using Active Directory) and the users are part of a group that has permissions to the server and database.

Your description and code suggests that Active Directory is not being used, so the best option to use is specifying a Username and Password in the connection string. These two values would have to be entered into your application via a dialog box, and then combined into the connection string to use to connect to the SQL Server.
 
Share this answer
 
You probably need to configure SQL Server with SQL Server Configuration Manager, make sure TCP/IP is enabled:
Configure a Server to Listen on a Specific TCP Port - SQL Server | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900