Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i am making a project of library management from a tutorial in youtube
and that guy use vb language and i am trying to make it in c# winform
now that guy use local data base and its format is .sdf and i add .mdf local database because i am using visual studio 2013

then he made a database-class in it he define connection string and other database related code

now he use this
in vb
public CLass DBMSClass
pivate DBMSConnectionString="inside connection string which he copy from database properties .sdf"
End Class
now i try to create exactly like it which is
class DBMSCLASS
{
//define connection string
private string DBMSConnectionString;

DBMSConnectionString="DataSource(LocalDB)\v11.0;AttachDbFilename="C:\\Users\\user-name\\documents\\visual studio 2013\\Projects\\library mangement system\\library mangement system\\LMS.mdf";Integrated Security=True");
}
now i am getting error from c:\\ to security=true"); this line are red but this is not red DataSource(LocalDB)\v11.0;AttachDbFilename
so someone can help me what is wrong in it.


for refernce video link https://www.youtube.com/watch?v=3qXLn7ZrllQ you can see at 20:01 minute of video
Posted
Updated 19-Sep-14 7:52am
v3
Comments
[no name] 19-Sep-14 14:10pm    
www.connectionstrings.com

1 solution

OK, there are a couple of problems here:
1) SDF is not VB specific: if's a database format which can be used by any .NET application, provided it has the SQLCE assemblies referenced. MDF files are Access databases and need different classes in your code, and well as a suitable ACE or JET driver installed - unless you are using SQL Server and attaching the DB that way. Even then, you will need SQLConnection, SQLCommand and suchlike objects to access it.
2) You can't just write a connection string like that!
C#
DBMSConnectionString="DataSource(LocalDB)\v11.0;AttachDbFilename="C:\\Users\\user-name\\documents\\visual studio 2013\\Projects\\library mangement system\\library mangement system\\LMS.mdf";Integrated Security=True");
I'm not possitive I know what you re trying to do there, but this might work a little better:
C#
DBMSConnectionString="DataSource(LocalDB)\v11.0;AttachDbFilename=\"C:\\Users\\user-name\\documents\\visual studio 2013\\Projects\\library mangement system\\library mangement system\\LMS.mdf\";Integrated Security=True");


But I'd start by creating a connection in VS and base it on the connections string from there:
1) Open the Server Explorer pane.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

Since you are attaching the file each time (why?) you may have to tweak this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900