c# filenotfoundexception on webbrowser? - c#

if (webBrowser1.DocumentText.IndexOf("Page: 1") != -1)
on the above line i am getting this exception
System.IO.FileNotFoundException was
unhandled Message="The system cannot
find the file specified. (Exception
from HRESULT: 0x80070002)"
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.IPersistStreamInit.Save(IStream
pstm, Boolean fClearDirty)
at System.Windows.Forms.WebBrowser.get_DocumentStream()
at System.Windows.Forms.WebBrowser.get_DocumentText()
at WindowsFormsApplication1.Form1.GenerateETGWorklists()
in C:\Documents and
Settings\agordon\My Documents\Visual
Studio
2008\Projects\GenerateWorklists\GenerateWorklists\Form1.cs:line
603
at WindowsFormsApplication1.Form1.btnProcess_Click(Object
sender, EventArgs e) in C:\Documents
and Settings\agordon\My
Documents\Visual Studio
2008\Projects\GenerateWorklists\GenerateWorklists\Form1.cs:line
55
at System.Windows.Forms.Control.OnClick(EventArgs
e)
at System.Windows.Forms.Button.OnClick(EventArgs
e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent)
at System.Windows.Forms.Control.WmMouseUp(Message&
m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message&
m)
at System.Windows.Forms.ButtonBase.WndProc(Message&
m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr
lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32
pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form
mainForm)
at WindowsFormsApplication1.Program.Main()
in C:\Documents and
Settings\agordon\My Documents\Visual
Studio
2008\Projects\GenerateWorklists\GenerateWorklists\Program.cs:line
18
at System.AppDomain._nExecuteAssembly(Assembly
assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String
assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback
callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
what is the meaning of this? i did not get this error yesterday and getting it today. the webpage opens no problem and the text Page: 1 is definitely there.
here is a similar issue also without solution
http://bytes.com/topic/c-sharp/answers/657812-webbrowser-documenttext-getting-problem

this is a known bug and microsoft doesn't do anything about it for vs2008 at least. here's a fix:
String lastsource = ((mshtml.HTMLDocumentClass)(((webBrowser1.Document.DomDocument)))).documentElement.innerHTML;
webBrowser1.Document.OpenNew(true);
webBrowser1.Document.Write(lastsource);
now we can access DocumentText with no problems
dont forget to import mshtml as a reference

Try webBrowser1.Document.Body.InnerText.

I too found it strange that the web browser control was throwing an exception related to file access, when I was loading a page from the web.
When looking into this, I noticed something strange:
This error is far less common when the temporary internet files have recently been cleared.
I modified my application so that it clears the temporary internet files automatically when the application starts, which was enough to resolve 90% of these errors.
My code for cleaning the temporary internet files is below... I don't think this will work on all operating systems - there may be a better way - but this suits my needs because it works on Server 2008.
(my code is in vb.net, but the c# version shouldn't be too hard to figure out.)
'start cleaning the temporary internet files
Dim clearFilesProcess As Process = System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255")
'wait for the temporary internet files to be deleted
While Not (clearFilesProcess.HasExited)
System.Threading.Thread.Sleep(200)
End While

Related

Using weka in C#: Unable to cast object of type 'java.util.ArrayList' to type 'System.Collections.Generic.List`

I am currently working on a project in which I need to use FP-Growth algorithm. I know Weka is a handy tool for it. However, I am using C# for coding (due to some other libraries I need). So, I converted weka.jar to weka.dll using IKVM.NET. Below is a code snippet that i have written:
FPGrowth FPMiner = new FPGrowth();
FPMiner.buildAssociations(dataset);
AssociationRules rules = FPMiner.getAssociationRules();
List<AssociationRule> rule = rules.getRules();
This gives me an error as:
Cannot implicitly convert type 'java.util.List' to
'System.Collections.Generic.List'.
An explicit conversion exists (are you missing a cast?)
So, I added a cast to the last line as:
List<AssociationRule> rule = (System.Collections.Generic.List<AssociationRule>)rules.getRules();
The error goes away but I get an exception when I run my code, saying:
System.InvalidCastException was unhandled Message=Unable to cast
object of type 'java.util.ArrayList' to type
System.Collections.Generic.List`1[weka.associations.AssociationRule]'.
Source=WindowsFormsApplication1
The stacktrace goes as:
StackTrace:
at DetectGroup.Form1.GenerateARFF() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 279
at DetectGroup.Form1.findNearestNeighbours() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 236
at DetectGroup.Form1.findSelectedTraj() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 165
at DetectGroup.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Form1.cs:line 404
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at DetectGroup.Program.Main() in C:\Users\user\Documents\Visual Studio 2010\Projects\DetectGroup\DetectGroup\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException:
I am unable to figure out what to do now. I have tried searching stuff but haven't yet got the solution. I understand that the error is because getRules() returns java.util.List while I am trying to use it as System.Collections.Generic.List. What can I do to avoid it? Any help would be great!
Also, is there any data mining library (like Weka) available in C#?
Thank you!
I am answering my own question. I used this link to solve the problem I was facing. Thanks #SecretSquirrel(see the comments) and #Jon Iles (see the answer I've linked).

System.Data.OleDb.OleDbException was unhandled: is not a valid path

This is my first attempt trying to access db files from the server. If run the program locally there are no problems
I stored ms access files on the server and I trying to run the program from my laptop and I am recieving the following error....
System.Data.OleDb.OleDbException was unhandled is not a valid path. Make sure that the path
name is spelled correctly and that you are connected to the server on which the file resides.
My connection string looks something like this...
myCon = new OleDbConnection(#"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\name-SERVER\SHAREDFILES\FileRDB.mdb; Jet OLEDB:System Database=system.mdw");
There has username and password for the server. Should I include this in the connection string?
Stacktrace looks like this...
System.Data.OleDb.OleDbException was unhandled
is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Source=Microsoft JET Database Engine
ErrorCode=-2147467259
StackTrace:
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 MALHRManagementSystem.FrmLogin.btnLogin_Click(Object sender, EventArgs e) in C:\Users\username\Desktop\Project\foldername\foldername\foldername\Form.cs:line 40
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at somefilename.Program.Main() in C:\Users\username\Desktop\Project\foldername\foldername\foldername\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Please can someone advise me how do I correct this problem.
Thanks in advance
I am not sure what tag I should use for this thread but please correct it if I am wrong here.
db is MS-Access 2003 and visual studio 2010
This is working now. To have a mapped network drive on vista/ Windows 7. Right click on My Computer > Map Network Drive > Select a drive > Click on Browse button . A menu appears as Browse For Folder -- Select a shared network folder. Then choose the network name and the folder. Once you have done that Click OK. That is all you have to do. Here are some useful links on howto if anyone is interested...
here
here
Vista

Close the main thread

I am doing restoration process through smo. After sucessful restoration i enable my database back
currentDb.SetOnline();
Problem is the database instance doesnt work after that. the instance failed to connect. So i thought y not i shutdown my application.
Application.Exit();
But writing the above code doesnt exist my app rather then i got exception. Details are
enter code hereSystem.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="VitoProject"
StackTrace:
at VitoProject.backAndRestore.restoreDatabase_Click(Object sender, EventArgs e) in C:\WorkSpace\VitoProject\VitoProject\backAndRestore.cs:line 176
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at VitoProject.Program.Main() in C:\WorkSpace\VitoProject\VitoProject\Program.cs:line 18
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
It might be not the best solution, but if you're trying to exit your application and something is getting hung, you may want to try;
Environment.Exit(1);

Attempted to read or write protected memory. - After converting app from VS 2005 to VS 2008

I have an application that was written in VS 2005 (C#). Works fine, it calls a 3rd Party dll. Now that I've converted it to VS 2008 (using the wizard), I get the following error when trying to instantiate the 3rd party dll.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Not sure where to even start debugging this. Can anyone point me in the right direction?
EDIT: As a side note it does the exact same thing under VS 2010.
EDIT: Both VS 2005 and VS 2008 projects using the same code target .NET 2.0 Framework
EDIt: It's an ActiveX library called LPDFCTRLLib. I've simply added it under References and create a new instance of it:
public LPDFCTRLLib.LPDFWndClass olpdf = null;
//and later in my code
//...
//this is where it fails
olpdf = new LPDFCTRLLib.LPDFWndClass();
EDIT: Stack Trace
at pcl2pdf.Form1.convertPCL(String inputFile, String outputFile) in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Form1.cs:line 29
at pcl2pdf.Form1.Form1_Load(Object sender, EventArgs e) in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Form1.cs:line 24
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.ContainerControl.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at pcl2pdf.Program.Main() in C:\junk\pcl2pdf\pcl2pdf\pcl2pdf\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
You should rempve the DLL and then re-Add it. Especially for an unmanaged DLL. And check with the supplier if it is compatible.
And please note: You do not convert Projects to a VS version, except maybe for the config file. You make it target a Framework version. Your question lacks all info about Fx versions.
Here is the same problem described: http://bloggingabout.net/blogs/dennis/archive/2009/06/08/attempted-to-read-or-write-protected-memory-in-a-net-application.aspx
"Anyway, the solution was to enable
JIT optimization. In other words, in
Visual Studio 2008 choose “Tools” and
then “Options”. Select “Debugging” and
“General” and find the line that says
“Suppress JIT optimization on module
load”. This kind of makes sure that
the debugger and the JIT compiled code
aren’t running out of sync because the
JIT compiler is such a super duper
optimizer of your code. This did the
trick."

Castle Active Record: SQL Express doesn't work. SQL Developer does

I've been trying to troubleshoot a Castle ActiveRecord exception for days now. Whenever I attempt to access the database I get an exception with an InnerException value of "An attempt to attach an auto-named database for file database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
I'm trying to connect to an SQL Server Express 2005 database. I don't have any other database option because the school computers only have SQL Express on them.
My connection settings
hibernate.connection.driver_class
NHibernate.Driver.SqlClientDriver
hibernate.dialect
NHibernate.Dialect.MsSql2005Dialect
hibernate.connection.provider
NHibernate.Connection.DriverConnectionProvider
hibernate.connection.connection_string
Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=database.mdf
This fails to work even if I set AttachDBFilename to an absolute path. User Instance has no effect. The database file is currently in the root of the project mixed in with my WinForms classes.
When using
hibernate.connection.connection_string
Data Source=localhost;Initial Catalog=FinalApp;Integrated Security=True;Pooling=False
I have no problems doing this on my laptop but I can't use the SQL Server 2005 Developer Edition on the school computers.
Full Stack Trace as requested
Castle.ActiveRecord.Framework.ActiveRecordException was unhandled
Message="Could not perform FindAll for Book"
Source="Castle.ActiveRecord"
StackTrace:
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order[] orders, ICriterion[] criteria) in c:\dev\castle\svn\branches\1.0.x\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:line 1022
at Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType) in c:\dev\castle\svn\branches\1.0.x\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:line 982
at Castle.ActiveRecord.ActiveRecordBase`1.FindAll() in c:\dev\castle\svn\branches\1.0.x\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordBase.Generic.cs:line 333
at CSharpFinal.InventoryMain.InventoryMain_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\CSharpFinal\InventoryMain.cs:line 36
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.ContainerControl.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at CSharpFinal.Form1.inventoryToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\CSharpFinal\Form1.cs:line 51
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CSharpFinal.Program.Main() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\CSharpFinal\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Castle.ActiveRecord.Framework.ActiveRecordException was unhandled
Message="Could not create the schema"
Source="Castle.ActiveRecord"
StackTrace:
at Castle.ActiveRecord.ActiveRecordStarter.CreateSchema() in c:\dev\castle\svn\branches\1.0.x\ActiveRecord\Castle.ActiveRecord\Framework\ActiveRecordStarter.cs:line 212
at CSharpFinal.Form1.reInitializeDatabaseToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\CSharpFinal\Form1.cs:line 65
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CSharpFinal.Program.Main() in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\CSharpFinal\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException.Message is "An attempt to attach an auto-named database for file database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
Hmmm, this is sort of a guess, but do you need to specify a database name?
(Initial Catalog in conn string)
It is probably becuase your SQL Express connection string is turning off user instance. If you leave user instance turned on then SQL will attach the database if required, if not it will just open it. If you turn it off then the attach is permenant. Any attempt to use the same connection string again will result in an error because the database already exists.
Becuase you have not attached the database by using that connection string, you will need to detach the database before you can then use the correct connection string.
I suggest you download SQL management studio express, if you haven't already got it. That will let you see the database already attached and detach it easily.
Okay, if that is not the problem can SQL server access the database file? Has it got permissions on that folder? It normally runs as network service, which you can grant access to the file just like any other user. You could eliminate the file permissions as an issue by granting full control to everyone, if that fixes it then you can tweak the permissions down to what is required. I would guess that the SQL server service account will require modify rights on the .mdf file. I don't know where it creates the .ldf for a user instance database. It might need create file rights in the same folder as the .mdf.

Categories

Resources