SQL database deployment for VB.NET app

前端 未结 2 523
野的像风
野的像风 2021-01-28 00:16

I have read many articles here, but haven\'t quite found the solution. I have a SQL Server Express database that is used by my VB.NET application. I have packaged and deployed t

相关标签:
2条回答
  • 2021-01-28 00:30

    You need to attach your database file to the running SQL Server on the client machine. This could be easily done using this variation on the connection string stored in your configuration file (app.config or web.config)

    Server=.\SQLExpress;AttachDbFilename=where_you_have_stored_the_mdf_file;
            Database=dbname; Trusted_Connection=Yes;
    

    in alternative, you could use the |DataDirectory| substitution string.
    This shortcut eliminates the need to hard-code the full path.
    Using DataDirectory, you can have the following connection string:

    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\yourfile.mdf”
             Database=dbname; Trusted_Connection=Yes;
    
    0 讨论(0)
  • 2021-01-28 00:41

    You should to attach your file to the Sql Server instance.

    CREATE DATABASE YourDatabaseName 
        ON (FILENAME = 'C:\your\data\directory\your_file.mdf'), 
        (FILENAME = 'C:\your\data\directory\your_file_Log.ldf') 
    FOR ATTACH; 
    
    0 讨论(0)
提交回复
热议问题