Troubleshooting
The errors a first project meets most often, as you see them, and what to do about each.
On this page
- macOS Does Not Open The App
- The Server Was Not Found
- Login Failed
- Cannot Open Database
- The Namespace Could Not Be Found
- Microsoft.SqlServer.Types Is Missing
- Unrecognized Escape Sequence
- The Certificate Chain Is Not Trusted
- No Connection String Is Registered
- A Navigation Property Is Null
- Still Stuck?
macOS Does Not Open The App#
The app is not signed yet, so macOS blocks it the first time: open it once, then go to System Settings > Privacy & Security and choose Open Anyway. On macOS 14 or earlier, right-click the app (or Control-click) and choose Open instead. See Installation.
The Server Was Not Found#
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.
The server name is wrong, or SQL Server is not running. LocalDB's name is (localdb)\MSSQLLocalDB;
a server on another port is written with a comma, as in localhost,14333; a stopped Docker container starts again with
docker start sharpfactory-sql. No SQL Server yet? See the sample database.
Login Failed#
Login failed for user 'sa'.
The user or the password is wrong. On macOS and Linux, Windows authentication needs Kerberos to be set up: without it,
turn off Windows authentication in the app (and leave Integrated Security out of your connection string)
and sign in with a SQL Server user, such as the Docker container's sa.
Cannot Open Database#
Cannot open database "SharpFactoryShop" requested by the login. The login failed.The server has no database with that name, or the name is misspelled. For the sample database, run its script first.
The Namespace Could Not Be Found#
error CS0246: The type or namespace name 'MyApp' could not be found (are you missing a using directive or an assembly reference?)
Your project does not reference the generated Repository project, or your root namespace is not
MyApp. Add the reference (with your root namespace and folder), and use your root namespace in the
using lines (see Namespaces):
dotnet add reference Dependencies/MyApp.Repository/MyApp.Repository.csprojMicrosoft.SqlServer.Types Is Missing#
error CS0234: The type or namespace name 'Types' does not exist in the namespace 'Microsoft.SqlServer' (are you missing an assembly reference?)The database has geography or geometry columns. Add the Microsoft.SqlServer.Types package to the generated Entity project (see Project Setup):
dotnet add package Microsoft.SqlServer.TypesUnrecognized Escape Sequence#
error CS1009: Unrecognized escape sequence
In a C# string, a backslash starts an escape. Write LocalDB's name as (localdb)\\MSSQLLocalDB, or start the string with @.
The Certificate Chain Is Not Trusted#
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
Since version 4.0, Microsoft.Data.SqlClient encrypts connections by default, and the server has no certificate
your computer trusts: common on development servers and in the Docker container. Add Encrypt=False to your
application's connection string, or TrustServerCertificate=True to keep the connection encrypted without checking the certificate.
The app itself connects without requiring encryption, so it reads the same database without this.
No Connection String Is Registered#
System.InvalidOperationException: No connection string is registered for the model with id 1. Call Database.RegisterModelConnectionString with that model's RepoLookup.ModelId and its connection string once, when the application starts, before the first query.Code generated before version 1.2.2.5 says instead:
System.Collections.Generic.KeyNotFoundException: The given key '1' was not present in the dictionary.The model's connection string was not registered before the first query; the number is the model's id from RepoLookup.ModelId. Call Database.RegisterModelConnectionString once, when the application starts, before using the repositories (see Project Setup).
A Navigation Property Is Null#
System.NullReferenceException: Object reference not set to an instance of an object.A navigation property is null when the query did not load it, and when there are no related rows: the Orders of a customer without orders. Add it to the query, and check for null before looping (see Navigation Properties).
Still Stuck?#
Ask on GitHub Discussions, or report an issue with the message and what you ran.
Something wrong or unclear on this page? Tell us on GitHub