I’m having some issues with my connection string. I’ve been testing a lot of different strings and approaches and now I’m stuck.
private static void InitializeSessionFactory()
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(
@"Server=Data Source=.\SQLEXPRESS;DataBase=carDB.mdf;User ID=sa;Password=xxxSecretxxx;")
.ShowSql()
)
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<Car>())
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, false))
.BuildSessionFactory();
}
(I know I shouldn’t be using ‘sa’ at all – why I’ve done so is solely because of lack of management software so I had to use the only account there were)
I am using a SQL Server Express database.
The exception I get is this:
An invalid or incomplete configuration was used while creating a SessionFactory.
Check PotentialReasons collection, and InnerException for more detail.
This is my inner exception
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: SQL Network Interfaces,
error: 26 – Error Locating Server/Instance Specified)
Does anyone know how I should approach this? I’ve spent hours trying to get this to work.
In the connection string, you don’t specify the database file but the database name. So it shouldn’t be
but
provided that the database really has the name
carDBand not some other likeCars.Also, I recommend using the
SqlConnectionStringBuilderclass to build connection strings, as it guarantees for syntactically correct connection strings.On a side note: You do know that you can install the management tools (like SQL Server Management Studio for SQL Server Express) for the Express edition, too? This makes things much easier.