// set up connection to the database
        myConnection = new System.Data.SqlClient.SqlConnection();
        myConnection.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Craig\\Desktop\\Project\\App_Data\\ASPNETDB.MDF;Integrated Security=True;User Instance=True;";

Hi this is my above connection string which works fine on my personal computer. I need to move the entrive Project folder to a different location which will not have access to the current address.
Could someone be so kind to invoke the server.mappath method into my string. I have tried my self but failed misserably.

I need a fast reponse

ty

kvprajapati commented: Urgent! Do not use that word. Please. -2

Recommended Answers

All 12 Replies

still struggling

// set up connection to the database
myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = " copy and past path only";


you know how can you get path ?
ok i will explain
1) go to tools and add sqldatasource
2) you can see small ->(arrow) in sql data source in your aspx form then go in configrationdata string
3) one dialogbox open select your data based if not in dropdown list then go in new connection string ......
4) you can see path in +connectionstring
copy the path and past myConnection.ConnectionString = " copy and past path only" add / in every place in path ok

Thanks
Jignesh Ahya
Ahmedabad

Hi, ive done just as you said and i still get error! maybee it because i not slept for two days but its frustrating.

Mayb if i post the string

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True

You can solve?

This is not Right

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True

Go to get the Path and show it to use and we will tell you how to fit in the connection string

im not sure what you mean?
Is this not as easy i think to change?
"Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Craig\\Desktop\\Project\\App_Data\\ASPNETDB.MDF;Integrated Security=True;User Instance=True;";

So what you mean is that is you go to explorer and paste this

C:\\Users\\Craig\\Desktop\\Project\\App_Data\\

It shows you the Folder with ASPNETDB.MDF File ? please Confirm

Yes the database works fine on my local machine, however I need the string to point to a relative location rather than specific file. I basically need to burn the folder to disc and with teh current string the connection will be looking for the folder on my c:/..

You what you want exactly is that you want to change the Connection-string without recompiling your application because the Connection string might change at anytime ?

I just want the connection string to map the server path.
It should not be point to a specific file location.

I am sorry you cannot understand

Use |DataDirectory|.

myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True;";

my friend this is not gonna work...

cos u r using the database in the appdata folder which got created..

using asp.net configuration wizard...if you are moving the stuff in to new machine then you need to do configure again that database using asp.net configuration wizard..

i hope this will help...i had the same situation 6 month ago..

commented: N.A +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.