what's the issue with AttachDbFilename

后端 未结 2 1765
抹茶落季
抹茶落季 2020-12-01 21:53

Apparently, using AttachDbFilename and user instance in your connection string is a bad way to connect to a DB. I\'m using SQL server express on my

2条回答
  •  失恋的感觉
    2020-12-01 22:41

    In case someone had the problem.

    When attaching the database with a connection string containing AttachDBFile with SQLEXPRESS, I noticed this connection was exclusive to the ASP.NET application that was using the database. The connection did block the access to all other processes on the file level when made with System.Data.SqlClient as provider.

    In order to assure the connection to be shareable with other processes instead use DataBase to specify the database name in your connection string Example or connection string :

    Data Source=.\SQLEXPRESS;DataBase=PlaCliGen;User ID=XXX;password=ZZZ; Connect Timeout=30 
    

    ,where PlaCliGen is the name (or logical name) by which SQLEXPRESS server knows the database.

    By connecting to the data base with AttachDBFile giving the path to the .mdf file (namely : replacing DataBase = PlacliGen by AttachDBFile = c:\vs\placligen\app_data\placligen.mdf) the File was connected exclusively and no other process could connect to the database.

提交回复
热议问题