当尝试在 C# 中创建 Enterprise Architect 插件时,在我完成代码并在 VS 2010 中运行它之后,我可以将记录添加到数据库或删除,但是当我使用同一个项目的插件项目时但是使用允许我访问 Enterprise Architect 事件的类库,我收到以下错误:
应用程序的组件中发生了未经处理的异常。如果您单击继续,应用程序将忽略此错误并尝试继续。
尝试为 C:\Program Files\Sparx Systems\EA\DataBase\DBMetric.mdf 附加自动命名数据库失败。存在同名数据库,或无法打开指定文件或其位于 UNC 共享上。
当我去的C\...EA
时候没有数据库文件夹!
这是我的app.config
文件
<configuration>
<connectionStrings>
<add name="WindowsFormsApplication19.Properties.Settings.DBMetricConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DataBase\DBMetric.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
这是我的连接字符串代码:
public static string myConnectionString = ConfigurationManager.ConnectionStrings["WindowsFormsApplication19.Properties.Settings.DBMetricConnectionString"].ConnectionString;
有任何想法吗?
提前致谢
这是类库
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EA;
using System.Windows.Forms;
using WindowsFormsApplication19;
namespace ClassLib
{
public class Class
{
// define menu constants
const string menuHeader = "-&Metrics";
const string menuOpen = "&Open";
// remember if we have to say hello or goodbye
private bool OPEN_TOOL = true;
///
/// Called Before EA starts to check Add-In Exists
/// Nothing is done here.
/// This operation needs to exists for the addin to work
///
/// <param name="Repository" />the EA repository
/// a string
public String EA_Connect(EA.Repository Repository)
{
//No special processing required.
return "a string";
}
///
/// Called when user Clicks Add-Ins Menu item from within EA.
/// Populates the Menu with our desired selections.
/// Location can be "TreeView" "MainMenu" or "Diagram".
///
/// <param name="Repository" />the repository
/// <param name="Location" />the location of the menu
/// <param name="MenuName" />the name of the menu
///
public object EA_GetMenuItems(EA.Repository Repository, string Location, string MenuName)
{
switch (MenuName)
{
// defines the top level menu option
case "":
return menuHeader;
// defines the submenu options
case menuHeader:
string[] subMenus = { menuOpen };//, menuGoodbye// };
return subMenus;
}
return "";
}
///
/// returns true if a project is currently opened
///
/// <param name="Repository" />the repository
/// true if a project is opened in EA
bool IsProjectOpen(EA.Repository Repository)
{
try
{
EA.Collection c = Repository.Models;
return true;
}
catch
{
return false;
}
}
///
/// Called once Menu has been opened to see what menu items should active.
///
/// <param name="Repository" />the repository
/// <param name="Location" />the location of the menu
/// <param name="MenuName" />the name of the menu
/// <param name="ItemName" />the name of the menu item
/// <param name="IsEnabled" />boolean indicating whethe the menu item is enabled
/// <param name="IsChecked" />boolean indicating whether the menu is checked
public void EA_GetMenuState(EA.Repository Repository, string Location, string MenuName, string ItemName, ref bool IsEnabled, ref bool IsChecked)
{
if (IsProjectOpen(Repository))
{
switch (ItemName)
{
// define the state of the hello menu option
case menuOpen:
IsEnabled = OPEN_TOOL;
break;
// define the state of the goodbye menu option
//case menuGoodbye:
// IsEnabled = !OPEN_TOOL;
// break;
// there shouldn't be any other, but just in case disable it.
default:
IsEnabled = false;
break;
}
}
else
{
// If no open project, disable all menu options
IsEnabled = false;
}
}
///
/// Called when user makes a selection in the menu.
/// This is your main exit point to the rest of your Add-in
///
/// <param name="Repository" />the repository
/// <param name="Location" />the location of the menu
/// <param name="MenuName" />the name of the menu
/// <param name="ItemName" />the name of the selected menu item
public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
{
switch (ItemName)
{
// user has clicked the menuOpen menu option
case menuOpen:
this.sayHello();
break;
// user has clicked the menuGoodbye menu option
//case menuGoodbye:
// this.sayGoodbye();
// break;
}
}
///
/// Say Hello to the world
///
private void sayHello()
{
//MessageBox.Show("MS.C Project");
Form1.frmMain.ShowDialog();
this.OPEN_TOOL = true;
}
///
/// Say Goodbye to the world
///
//private void sayGoodbye()
//{
// MessageBox.Show("MS.C Project Close");
// Form1.frm1.Hide();
// this.OPEN_TOOL = true;
//}
///
/// EA calls this operation when it exists. Can be used to do some cleanup work.
///
public void EA_Disconnect()
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}