Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All,

I am using VS2008,C# .net,Sql Server and Window form application.

Can we access sqlserver database file (.mdf) from pendrive or cd.

any suggestion or idea plz give me...

Help will be appreciated.......

Regards
Mukesh
Posted
Updated 21-Sep-16 21:41pm
v3
Comments
[no name] 17-Apr-12 7:50am    
What you are describing does not make any sense. Having a database on a CD is nonsensical. Connection strings do not use "paths" for database files. Oddly enough, connection strings are used to connect to the database server. Either you do not have a good idea on how databases work or whatever it is that you think you want to do is just plain bad.
Member 12753307 22-Sep-16 3:41am    
Before you answer/comment please study first. Read my answer..
[no name] 22-Sep-16 7:01am    
How about you learn to read first.
Mantu Singh 17-Apr-12 9:04am    
Before attaching the database u need to ensure it is on writable media like hard disk otherwise you wont be able to update any data......
Manoj Kumar Choubey 20-Apr-12 6:10am    
I am little Agree with Mantu singh .....

You will need to add the database to SQL server. You cannot just access it via file, it needs to be hosted in SQL. Your connection string will point to the SQL database, not the SQL database file.

Look at how to attach a db[^]. After you attach the db to a SQL instance you can then use a connection string to get to it.
 
Share this answer
 
Hi,
If you want to access your database file (.mdf) from CD or Pen Drive, you have yo attach your database with Sql server first.
To know how to attach database use link
Attach database
once your database is attached with Sql server, then you can easily access it using connection string.
 
Share this answer
 
Hello

Yes it is possible to do this thing, but one this you have to keep in mind is that the drive for that particular pendrive or CD must be same every time other wise it will show error during Connection.
 
Share this answer
 
yes--Possible (I'm assuming that client have .Net Framework installed and also SQL SERVER)

Write connection string in app.config file
By changing path of string in app.config you access that database.

Regards
Kul
 
Share this answer
 
Comments
Manoj Kumar Choubey 20-Apr-12 6:07am    
how is it possible , can you elaborate more ....
do you experiment .... ?
Kuldeep B 24-Apr-12 11:28am    
sorry yar its possible with access db....
u can do it without connection string .in place of connection string use the path of .mdf file

the client must have the sql server
and your when u create your .mdf file dont use pass
u can search in google for more tutorial
 
Share this answer
 
Here the thing we can access .mdf database file from any drive you want even from cd.
But if your accessing database from cd then your cd need to be "rewritable".
Because if its not then you can only access database but can't update database.

To access database from any drive just replace the drive letter in connection string with the drive letter where your database file (*.mdf) resides.

Example :

You cant use it by directly creating object

SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\dirname\databsename.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");


Or from app.config file : just put physical path of database
 
Share this answer
 
v2
Comments
Richard MacCutchan 22-Sep-16 4:29am    
Please do not post in old dead questions. This one is FOUR years old.

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