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:
make sure mdf file created same or older version of sql server 1 installed on target machine.
make sure sql server on target machine doesn't have database same name.
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.you may want |datadirectory| feature too, intsead of
getcurrentdirectory()
.
Comments
Post a Comment