Инициализатор типа выдал исключение - PullRequest
1 голос
/ 19 ноября 2011

Я пишу приложение на C # с использованием SQL Server CE. Evrtting прекрасно работает, и теперь я получаю следующее исключение: " Инициализатор типа для 'VideoStoreManager.AppData.DataBaseManager' вызвал исключение. " для этой строки кода: DataBaseManager.Connection.Open ();

Вот и все исключение:

System.TypeInitializationException was unhandled
  Message="The type initializer for 'VideoStoreManager.AppData.DataBaseManager' threw an exception."
  Source="VideoStoreManager"
  TypeName="VideoStoreManager.AppData.DataBaseManager"
  StackTrace:
   at VideoStoreManager.AppData.DataBaseManager.get_Connection()
   at VideoStoreManager.Security.SecurityManager.AuthenticateUser(String username, String password) in D:\Владиславко\Четвърти курс\Разпределени приложения\Video Store Manager\VideoStoreManager\Security\SecurityManager.cs:line 51
   at VideoStoreManager.GUI.Forms.frmLogin.btnLogin_Click(Object sender, EventArgs e) in D:\Владиславко\Четвърти курс\Разпределени приложения\Video Store Manager\VideoStoreManager\GUI\Forms\frmLogin.cs:line 40
   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.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.Form.ShowDialog(IWin32Window owner)
   at VideoStoreManager.Program.Main() in D:\Владиславко\Четвърти курс\Разпределени приложения\Video Store Manager\VideoStoreManager\Program.cs:line 26
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ArgumentException
   Message="Format of the initialization string does not conform to specification starting at index 0."
   Source="System.Data.SqlServerCe"
   StackTrace:
        at System.Data.SqlServerCe.ConStringUtil.GetKeyValuePair(Char[] connectionString, Int32 currentPosition, String& key, Char[] valuebuf, Int32& vallength, Boolean& isempty)
        at System.Data.SqlServerCe.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values)
        at System.Data.SqlServerCe.ConStringUtil.ParseConnectionString(String& connectionString)
        at System.Data.SqlServerCe.SqlCeConnection.set_ConnectionString(String value)
        at VideoStoreManager.AppData.DataBaseManager..cctor() in D:\Владиславко\Четвърти курс\Разпределени приложения\Video Store Manager\VideoStoreManager\AppData\DataBaseManager.cs:line 28
   InnerException:

Ответы [ 2 ]

3 голосов
/ 19 ноября 2011

Проблема в том, что ваша строка подключения недопустима для SqlServerCe. Из внутреннего исключения:

"Format of the initialization string does not conform to specification starting at index 0."

1 голос
/ 20 ноября 2011

проверьте эту ссылку, это всегда помогло мне

http://www.connectionstrings.com/sql-server-2005-ce

и http://www.connectionstrings.com хорошо для всех видов соединений с БД

На этом сайте есть похожие вопросы / ответы, проверьте, помогают ли они

Формат строки инициализации не соответствует спецификации, начиная с индекса 0

Форматстрока инициализации не соответствует спецификации, начиная с индекса 0. Не уверены, что это такое?

Подробнее о строке подключения в MSDN http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

...