Error after Publish

Posted 27 January 2011 - 05:21 PM

Hi all,
I am getting a error when publishing my application in regards to my database. I have isolated the problem i just don't know how to fix it. the error occurs because my program can't find my database (simple enough). I am using a typed database and have opened my app.config and found my connection string which is here

Re: Error after Publish

Posted 31 January 2011 - 11:20 AM

this happens when? when you try to run it on other machine? if so are you sure they have the framework? i`m little confused though your DB is where? Instead of using fixed paths why dont you put your DB in your application directory and use Application.StartupPath() to get your application startup path (lol) and use it something like this:

Re: Error after Publish

Posted 31 January 2011 - 11:27 AM

Hi, Right now I am only deploying it to my own pc to make sure all the bugs are out. My .net is updated so it should work, and it loads the first page of the program fine but when you try to access the database it throws that error. My problem is that Application.StartupPath doesn't work in the app.config XML file. Since I am using a typed database that is where my connection String is located. I am not really sure what to do from here.

Re: Error after Publish

Posted 31 January 2011 - 11:37 AM

oh so that is xml file lol how did i not notice
see dude you should not make config file until you first run your application. the best way is to check if the file exist if not make a default values for your program. i have never rly used app.config but you can make your own( best in my opinion) config file (xml, ini, txt etc what ever extension you like) write in your option that your program will have. in your program first thing that you should do is check if your config file exist if not create it with default values(in your case the connection string to your database) and then if you want can let the user select and change them in your program. Something like this:

Dim strCnn As String = String.Empty
If System.IO.File.Exists(Application.StartupPath & "\Config.xml") = False Then
'Create the default values'
strCnn = "connection string here..."
'Dont forget to write it in xml file after this otherwise it will create default always'
Else
'the file exist you can read your connection string from it'
End If

Re: Error after Publish

Posted 31 January 2011 - 11:48 AM

no you should not delete your app.config file you should just make your own file that you will store the database connection string. and yes you should do that when your main form start(initial components or form load function when ever you choice) i usually use main sub witch do this first and then run my programs (in C# you must have main function alway VB.NET is slacking and you can or dont use it)

Re: Error after Publish

Posted 31 January 2011 - 11:57 AM

something simple will do. the bonus of making your own config file is that you can modify it as you want. it can hold what ever you want and looks like you wants to look. the other thing that you benefit from is that you can write it where ever you want. the last thing is very useful if your writing application that will run on windows 7 or vista. as we know the user will mostly install it in program files and in vista and windows 7 you need admin. rights to write in there (update files) so instead of making the user to run your app. as admin you can check the version of the windows and if its bigger then windows xp you can write it in safer directory like my documents or something

Re: Error after Publish

Posted 31 January 2011 - 12:11 PM

The other thing I am kinda confused about is the clickonce deployment. My Config.xml goes in my Debug folder, after clickOnce deployment, where do the files get installed afterwards? I am also confused what you mean by the Don't forget to write it in the xml file part. Do I write a config.xml with the connection string if it doesn't already exist in the directory and how does that look code wise. Sorry if i am asking too much, I am a newer coder and a student( learning xml in one of my classes now) and unfortunately we have never deployed our applications just submitted HW by submitting our entire project folder.

Re: Error after Publish

Posted 31 January 2011 - 12:19 PM

See dude what i mean is that if you use that file you dont need to install it all you need to do is to get your database in your install folder. after this as i say check if your file exist (on first run after your program is installed it dose not) and you create your file with default values:

Dim strCnn As String = String.Empty
If System.IO.File.Exists(Application.StartupPath & "\Config.xml") = False Then
'Here first run the file dose not exist'
'create the default values'
strCnn = "connection string here..."
'Here you write the file so the next time your program starts it will exist'
'Dont forget to write it in xml file after this otherwise it will create default values always and the user will not be able to change the database path etc. options'
CreateMyXmlFileFunction(strCnn, OtherOption, ...)
Else
'the file exist you can read your connection string from it'
End If

Re: Error after Publish

Posted 31 January 2011 - 12:42 PM

Ok, so i add that code in the Form loading event.
I then Publish my Application via Clickonce
After installing my application I put the config.xml in the folder where my application is installed and of course i have to make sure my database is also in that folder.
Then when running my application it will check for the config.xml if it finds it, it loads the connection string from there and everything runs great. if not it creates its own and writes it to that folder for the future.

Now my last question is, is there anyway to automate this process so that when i do deploy my application to a friend or customer in the future, it can just be a click and install without the extra work.