sql server - Use .MDF file in c# -


i have .mdf file. want use in c# in desktop application.

this connection string :

string cwd = system.io.directory.getcurrentdirectory(); string constring = @"data source=.\sqlexpress; attachdbfilename=" + cwd + "\\salaryprogram.mdf;integrated security=true;user instance=true"; 

how can use .mdf file in c# ?

i getting error :

an attempt attach auto-named database file d:\naresh backup\salaryprogram\latest work\salaryprogram\salaryprogram\bin\debug\salaryprogram.mdf failed. database same name exists, or specified file cannot opened, or located on unc share.

thanks in advance.

check following 3 things:

  1. make sure mdf file created same or older version of sql server 1 installed on target machine.

  2. make sure sql server on target machine doesn't have database same name.

  3. always prefer path.combine() on direct concatenation of folder path , file name. function returns ending backslash character part of path, other times doesn't. direct concatenation can result in illegal paths.

  4. you may want |datadirectory| feature too, intsead of getcurrentdirectory().


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -