right now I have the appconfig as
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Documents and Settings\z1083774\Desktop\Data
\Database.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
I know I can put it in the root directory c:\ ,but i know there is another way to do it.

Sam HobbsRank #107 · 20.5K reputationPosted Mar 17, 2010, 10:34 AM EDT
David SmithRank #999 · 2K reputationPosted Mar 17, 2010, 2:05 PM EDT
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 17, 2010, 9:14 PM EDT
AttachDbFilename="\Data\Database.mdf";
Either create a folder names Data in the same folder where the exe is and set the path like this then you don't have to change the path every time you installed it.
Hope it helps you.
David SmithRank #999 · 2K reputationPosted Mar 19, 2010, 11:23 PM EDT
[global::System.Configuration.DefaultSettingValueAttribute("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"C:\\Data\\bin\\Debug\\Database.mdf\";Integrated Security=True;Conne" +
"ct Timeout=30;User Instance=True")]
and then in the appconfig I do this
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Cif_Clu_Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
providerName="System.Data.SqlClient" />
how can i set it up to where they can just run the exe anywhere on the computer, what if they wanted to run the exe on the desktop, that mean they would to create a datafolder i dont want to do that,
just want to run from anywhere.
David SmithRank #999 · 2K reputationPosted Mar 20, 2010, 12:21 AM EDT
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 20, 2010, 1:04 AM EDT
try this:
|DataDirectory| is a substitution string that indicates the path to the database.
By default, |DataDirectory| is substituted with the base directory that the exe is running from.
you can set the custom path of its byusing this code(use this code on load time of your application):
AppDomain.CurrentDomain.setData("DataDirectory","C:\\Data\\bin\\Debug\");
and than write this connection string in your appconfig:
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Cif_Clu_Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
thanks
please mark as answere if you like my answere
David SmithRank #999 · 2K reputationPosted Mar 20, 2010, 8:10 AM EDT
Ok I have questions regarding your last reply so with this line of code below , does this mean they can run the executive from anywhere , whether its on the desk, in a temp directory no matter what. right how I got to set up is they have to have the .mdf file along with executive to run the .exe .
AppDomain.CurrentDomain.setData("DataDirectory","C:\\Data\\bin\\Debug\");
hello Darnell
try this:
|DataDirectory| is a substitution string that indicates the path to the database.
By default, |DataDirectory| is substituted with the base directory that the exe is running from.
you can set the custom path of its byusing this code(use this code on load time of your application):
AppDomain.CurrentDomain.setData("DataDirectory","C:\\Data\\bin\\Debug\");
and than write this connection string in your appconfig:
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Cif_Clu_Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
thanks
David SmithRank #999 · 2K reputationPosted Mar 20, 2010, 8:13 AM EDT
AppDomain.CurrentDomain.SetData("DataDirectory","C:\\Data\\bin\\Debug\\");
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 21, 2010, 9:33 PM EDT
you can place this line on your application startup form file for example if you are using any login form than you can place this line on login form load event or you can use in program.cs file.
thanks
David SmithRank #999 · 2K reputationPosted Mar 22, 2010, 12:07 AM EDT
use this
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|CLU_OpDatabase.mdb"
so now im forcing the users to run the database where the exe is. which is what i prefer for this situation
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 22, 2010, 12:42 AM EDT
Hello Darnell
Please tell me how to distribute your application among your customer? with the help of setup file and database file or exe and databasefile???
thanks
BangaruBabu PuretiRank #2,987 · 483 reputationPosted Mar 22, 2010, 12:56 AM EDT
Let Me Explain
There is Beautiful Class Available in C# Windows To Detect Application Path Where The exe Gets installed
System.Windows.Forms.Application.StartupPath.ToString();
That Returns The Path As A String For Ur Application.U Just Append That mdf file name to The string.
example
=====
string constring=System.Windows.Forms.Application.StartupPath.ToString();
I Think it Resolves Ur Requirement.
feedback Always Expected
BangaruBabu Pureti
Sam HobbsRank #107 · 20.5K reputationPosted Mar 22, 2010, 5:40 PM EDT