FWTools/GDAL error in release version - c#

I'm using FWTools and SharpMap (with gdal_sharp) to build an application. And I have a weird error. Loading a raster layer runs great in Debug mode, but in Release it throws an Exception in SharpMap.Layers.GdalRasterLayer in the constructor when calling
_projectionWkt = _gdalDataset.GetProjectionRef();
The full exception is:
{System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at OSGeo.GDAL.GdalPINVOKE.Dataset_GetProjectionRef(HandleRef jarg1)
at OSGeo.GDAL.Dataset.GetProjectionRef()
at SharpMap.Layers.GdalRasterLayer..ctor(String strLayerName, String imageFilename) in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\SharpMap.Extensions\Layers\GdalRasterLayer.cs:line 404
at GreenGIS.Form1.addRasterLayer() in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Form1.cs:line 50
at GreenGIS.Form1.toolStripButtonAddVector_Click(Object sender, EventArgs e) in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Form1.cs:line 129
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.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.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.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)
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 GreenGIS.Program.Main() in d:\Fakultet\IX Semestar\GIS\Projekat\GreenGIS\GreenGIS\Program.cs:line 19}
The weird thing is that in Debug everything works fine. The build setup is exact, both .Net 4.0, x86 Platform.
Any ideas?
Thankyou in advance

I ran into similar problems but after using the current compiled binaries from Link the problem was fixed. I documented the steps that worked for me at http://vipassanaandenvironmentalinformatics.blogspot.co.nz/2013/03/getting-started-with-c-and-gdal.html.
Hope this answer is still of help to others.

It seems to be a problem with Windows 8 and it's DEP implementation along with .Net 4.0. I'm using a C++ dll in a wrapper, and the OS does not let it execute. It could be solved by editing the DLL or turning Data Execution Prevention off.

Related

Load Report Failed when importing .rpt file

So I'm trying to load an .rpt file to my c# project by setting the datasource as the rpt file. But the problem is I get an error saying;
CrystalDecisions.Shared.CrystalReportsException: 'Load report failed.'
Here is the complete error code that is showing
CrystalDecisions.Shared.CrystalReportsException
HResult=0x80131600
Message=Load report failed.
Source=CrystalDecisions.CrystalReports.Engine
StackTrace:
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at payrollsystemLatest.viewcr.button1_Click(Object sender, EventArgs e) in D:\echosystem\1080proll(new)\payrollsystemLatest\viewcr.cs:line 30
at System.Windows.Forms.Control.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.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 payrollsystemLatest.Program.Main() in D:\echosystem\1080proll(new)\payrollsystemLatest\Program.cs:line 21
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
COMException: Unable to load report.
Here is my code to load the rpt file to the viewer
ReportDocument rpt = new ReportDocument();
rpt.Load(#"D:\sample.rpt");
reportviewer.ReportSource = rpt;
reportviewer.Refresh()
So far, I have tried;
Double checking my destination where the .rpt file is
Deleting everything in the TEMP folder
Setting my printjob to -1
And reinstalling both 32 and 64 bit runtime
Any ideas how to fix this? Any help are appriciated!

Try to change Printer of my old application windows fourm

I designed a Windows form application many years ago, and due to my lack of experience in programming and not following some professional programming tips to debug it, also I have lost the project source code. I know I had statically defined the printer name in the software, how can I access my source code?
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
CrystalDecisions.Shared.CrystalReportsException: Load report failed. ---> System.Runtime.InteropServices.COMException (0x80004005): The system cannot find the path specified.
at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options)
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
--- End of inner exception stack trace ---
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename, OpenReportMethod openMethod, Int16 parentJob)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.Load(String filename)
at MehrPouyan.ServiceForm.SendPrint()
at MehrPouyan.ServiceForm.btnPrint_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.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.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
I solved my problem by decompiling my software and used this link to decompile

.NET WinForms: Cound not load System.Runtime

I was writing an app for a friend who wanted an easy way to use Morse Code.
I was attempting to use an External Library that I wrote with Morse Code support, and when I try to call it, I get this error, in an External "Control.cs" file. I found happened in both Visual Studio and JB Rider, though Visual Studio gives a different error as it can't debug external sources.
My usings are:
using CainsSharpTools; // <= This is my Library
using System.Diagnostics;
using System.Windows.Forms;
And my function call looks like this:
private void buttonEncode_Click(object sender, System.EventArgs e)
=> textBoxMorse.Text = MorseCode.Parse(textBoxPlain.Text).Value;
The error is
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at at MorseCoder.Form1.buttonEncode_Click(Object sender, EventArgs e)
at at System.Windows.Forms.Control.OnClick(EventArgs e)
at at System.Windows.Forms.Button.OnClick(EventArgs e)
at at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at at System.Windows.Forms.Control.WndProc(Message& m)
at at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at at System.Windows.Forms.Button.WndProc(Message& m)
at at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at at System.Windows.Forms.Application.Run(Form mainForm)
at MorseCoder.Program.Main() in C:\Users\caina\source\repos\MorseCoder\MorseCoder\Program.cs:19
i needed to use .NET Standard with my Lib

c# filenotfoundexception on webbrowser?

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

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