13 Replies - 3468 Views - Last Post: 31 January 2011 - 12:56 PM Rate Topic: -----

#1 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

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
<add name="SargeApplication.My.MySettings.Pi_Lam_DatabaseConnectionString"
            connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;|DataDirectory|\Pi Lam Database.accdb&quot;;Persist Security Info=True"
            providerName="System.Data.OleDb" />

here is the error info

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Data.OleDb.OleDbException (0x80004005): Could not find file 'C:\Users\Milad Soufastai\AppData\Local\Apps\2.0\Data\TP71P6JO.K4N\KPEZELNC.7V5\pila..tion_235606b050b62b3f_0001.0000_4158f152ef84c7ee\Data\Pi Lam Database.accdb'.
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, Commandbehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, Commandbehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at SargeApplication.Pi_Lam_DatabaseDataSetTableAdapters.PointListTableAdapter.Fill(PointListDataTable dataTable)
at SargeApplication.Database.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.onload(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Pi Lambda Phi- Sargeant At Arms
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/Milad%20Soufastai/AppData/Local/Apps/2.0/WLK2GBDA.09M/844N8GGZ.59B/pila..tion_235606b050b62b3f_0001.0000_4158f152ef84c7ee/Pi%20Lambda%20Phi-%20Sargeant%20At%20Arms.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 10.0.0.0
Win32 Version: 10.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Data.DataSetExtensions
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Numerics
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Transactions
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll

My question is how can i fix it? I think that if i do Application.StartupPath instead of |DataDirectory| it would work, but i tried it to no avail. Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Error after Publish

#2 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

Re: Error after Publish

Posted 31 January 2011 - 11:11 AM

Hi all,

Anybody have an idea on this, I am really stuck and would appreciate it.
Was This Post Helpful? 0
  • +
  • -

#3 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

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:
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\MyDB.accdb;Persist Security Info=True"
            providerName="System.Data.OleDb"



EDIT:
I`m not sure about \MyDB.accdb if it need "\" though

This post has been edited by NoBrain: 31 January 2011 - 11:21 AM

Was This Post Helpful? 1
  • +
  • -

#4 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

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.
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Error after Publish

Posted 31 January 2011 - 11:37 AM

oh so that is xml file lol how did i not notice :D
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


This post has been edited by NoBrain: 31 January 2011 - 11:40 AM

Was This Post Helpful? 1
  • +
  • -

#6 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

Re: Error after Publish

Posted 31 January 2011 - 11:41 AM

Wait so if I understand Correctly, I should delete the app.config that VS2010 built for me. Then create my own XML with the proper connection string.

Also, where should i put that piece of code? On the initialize for the main form.
Was This Post Helpful? 0
  • +
  • -

#7 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

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)
Was This Post Helpful? 1
  • +
  • -

#8 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

Re: Error after Publish

Posted 31 January 2011 - 11:53 AM

Hi Sorry if this a stupid question, but the config.xml file that i make, should that be in the same format as the app.config or just something simple like
<connection>
 <connectionstring="Provider=Microsoft.Ace.Oledb.12.0;Data Source="& Application.StartupPath & "\Pi Lam Database.accdb" />
</connection>


Edit: Sorry had to add code tags

This post has been edited by mils180: 31 January 2011 - 11:55 AM

Was This Post Helpful? 0
  • +
  • -

#9 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

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 :)
Was This Post Helpful? 1
  • +
  • -

#10 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

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.
Was This Post Helpful? 0
  • +
  • -

#11 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

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


Was This Post Helpful? 0
  • +
  • -

#12 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

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.
Was This Post Helpful? 0
  • +
  • -

#13 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Error after Publish

Posted 31 January 2011 - 12:52 PM

i quick seach throw this out:
http://answers.yahoo...28014202AApYDd6
Was This Post Helpful? 0
  • +
  • -

#14 mils180  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 38
  • Joined: 19-November 10

Re: Error after Publish

Posted 31 January 2011 - 12:56 PM

Hi,
the link that the yahoo answer points to is dead, http://gujarati.allnsole.com/
also my database is in my bin/debug/ folder.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1