Reputation: 17
I have a UWP C# app and I need to connect to my SQL Server Express database.
When I connect to the database from tools option in Visual Studio, I can copy the connection string. Connectivity tests successfully, but when I try to connect with code I always get this error:
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)
string connectionString =
@"Data Source=DESKTOP-IF672GA\SQLEXPRESS;Initial Catalog=TestDatabase;Integrated Security=True";
SqlConnection sc = new SqlConnection(connectionString);
sc.Open();
Upvotes: 0
Views: 706
Reputation: 998
enable Named Pipes, and TCP/IP.
If not work, Open the Package.appxmanifest file of your UWP project in the manifest designer. In the Capabilities tab, select the Enterprise Authentication checkbox if you are using Windows Authentication for authenticating your SQL Server. and following:
Upvotes: 0
Reputation: 2358
I can reproduce your issue when I use Windows authentication. Could you please try to use SQL Server authentication instead of Windows authentication?
As follows:
string connectionString =@"Data Source = DESKTOP-IF672GA\SQLEXPRESS;Initial Catalog = TestDatabase;User ID=xxx;Password=xxxxx";
Upvotes: 0