|
-
May 26th, 2021, 01:28 AM
#1
Thread Starter
Banned
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
-
May 26th, 2021, 01:52 AM
#2
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|