Results 1 to 2 of 2

Thread: How to include .mdf inside vb.net without using SQL Express on other users machines

  1. #1

    Thread Starter
    Banned
    Join Date
    Apr 2020
    Location
    https://t.me/pump_upp
    Posts
    61

    How to include .mdf inside vb.net without using SQL Express on other users machines

    Dear All

    When I Add .mdf file inside VB.net Application Under the Debug Folder and refer to it using this code

    Code:
    mycon = New SqlConnection("Data Source=.;Initial Catalog=" & Application.StartupPath  & "\Projects.mdf;Integrated Security=True;")
    The Connection Does not Work, So What is missing for me to do,

    Notice : I Checked all answers on the internet and I tried many things but nothing works,

    Appreciate your help.

    Thanks, Regards

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to include .mdf inside vb.net without using SQL Express on other users machin

    Of course nothing works, because you're trying to do something impossible. Notice that when you add an MDF file to your project the item template is labeled "Service-Based Database"? If you have no server then you have no database.

    If you want to deploy an MDF data file with your app then you need as local instance of SQL Server to attach it to at run time. I've never tried with anything but SQL Server Express so I'm not 100% sure it works with other editions. If you don't want to have to have SQL Server installed then you can't use a SQL Server MDF data file. You'll need to use a file-based database, which probably means Jet/Access or SQLite, although there are other options. If you use an MDB file then the Jet engine is basically part of Windows, although you're limited to 32-bit. If you use an ACCDB file then you need the ACE engine installed, which it will be if Office is installed. You are then limited to the same bitness as Office, which will usually be 32-bit. You can install ACE standalone as either 32-bit or 64-bit. If you use SQLite then the database engine is deployed as a DLL with your application, added as a NuGet package.

    If you do want to stick with an MDF file and use SQL Server Express then you need to use a proper connection string. That means using AttachDbFilename and not Initial Catalog. You should also use "|DataDirectory|" for the folder path if the data file is in the same folder as your application EXE.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width