Connection String to Connect to .MDF

后端 未结 3 1097
名媛妹妹
名媛妹妹 2020-12-10 02:16

I\'ve created a new project in VS2008, and added a .MDF file to the project. This is the first time I\'ve tried to use the MDF files and .SQLEXPRESS databases (I\'ve always

相关标签:
3条回答
  • 2020-12-10 02:45

    from where this name mydbfile ?

    If you're using the *.mdf file in the App_Data folder of an ASP.NET app you can use this.

    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|**mydbfile**.mdf;Database=dbname; Trusted_Connection=Yes;
    

    If it's not an ASP.NET application don't use the DataDirectory syntax and just use the full c:... path.

    0 讨论(0)
  • 2020-12-10 02:54

    If you're using the *.mdf file in the App_Data folder of an ASP.NET app you can use this.

    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

    If it's not an ASP.NET application don't use the DataDirectory syntax and just use the full c:\... path.

    0 讨论(0)
  • 2020-12-10 03:07

    For a local DB and no SQLEXPRESS server:

    "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=""|DataDirectory|\MyDB.mdf"";Integrated Security=True;Connect Timeout=30"
    
    0 讨论(0)
提交回复
热议问题