C# 尝试在windows应用程序中附加自动命名数据库
尝试在C#中创建企业架构师外接程序时,在我完成代码并在VS 2010中运行后,我可以将记录添加到数据库或删除,但当我使用外接程序项目时,它是同一个项目,但具有允许我访问企业架构师事件的类库,我会遇到以下错误: 应用程序中的组件发生了未经处理的异常。 如果单击“继续”,应用程序将忽略此错误并 试图继续 尝试为C:\Program Files\Sparx附加自动命名数据库 Systems\EA\DataBase\DBMetric.mdf失败。同名数据库 存在,或指定的文件无法打开或位于UNC上 分享 当我转到C# 尝试在windows应用程序中附加自动命名数据库,c#,database,ado.net,enterprise-architect,C#,Database,Ado.net,Enterprise Architect,尝试在C#中创建企业架构师外接程序时,在我完成代码并在VS 2010中运行后,我可以将记录添加到数据库或删除,但当我使用外接程序项目时,它是同一个项目,但具有允许我访问企业架构师事件的类库,我会遇到以下错误: 应用程序中的组件发生了未经处理的异常。 如果单击“继续”,应用程序将忽略此错误并 试图继续 尝试为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>
有什么想法吗
提前谢谢
这是类库
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();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用EA;
使用System.Windows.Forms;
使用WindowsFormsApplication19;
名称空间类库
{
公共课
{
//定义菜单常量
常量字符串menuHeader=“-&Metrics”;
常量字符串menuOpen=“&Open”;
//记住,如果我们必须说你好或再见
私有bool OPEN_TOOL=true;
///
///在EA开始检查外接程序存在之前调用
///这里什么也没做。
///此操作必须存在,加载项才能工作
///
///EA存储库
///一串
公共字符串EA_Connect(EA.Repository)
{
//无需特殊处理。
返回“字符串”;
}
///
///当用户从EA中单击外接程序菜单项时调用。
///用我们想要的选择填充菜单。
///位置可以是“树视图”、“主菜单”或“图表”。
///
///存储库
///菜单的位置
///菜单的名称
///
公共对象EA_GetMenuItems(EA.Repository Repository,string Location,string MenuName)
{
开关(菜单名)
{
//定义顶级菜单选项
案例“”:
返回菜单头;
//定义子菜单选项
case menuHeader:
字符串[]子菜单={menuOpen};//,menuGoodbye/};
返回子菜单;
}
返回“”;
}
///
///如果项目当前已打开,则返回true
///
///存储库
///如果在EA中打开项目,则为true
bool IsProjectOpen(EA.Repository)
{
尝试
{
EA.Collection c=Repository.Models;
返回true;
}
抓住
{
返回false;
}
}
///
///打开菜单后调用,查看哪些菜单项应处于活动状态。
///
///存储库
///菜单的位置
///菜单的名称
///菜单项的名称
///指示菜单项何时启用的布尔值
///指示是否选中菜单的布尔值
public void EA_GetMenuState(EA.Repository Repository,string Location,string MenuName,string ItemName,ref bool已启用,ref bool已检查)
{
如果(IsProjectOpen(存储库))
{
开关(项目名称)
{
//定义hello菜单选项的状态
案例MENOOPEN:
IsEnabled=打开工具;
打破
//定义“再见”菜单选项的状态
//案例说明:
//IsEnabled=!打开工具;
//中断;
//不应该有任何其他的,但以防万一禁用它。
违约:
IsEnabled=false;
打破
}
}
其他的
{
//如果没有打开的项目,请禁用所有菜单选项
IsEnabled=false;
}
}
///
///当用户在菜单中进行选择时调用。
///这是外接程序其余部分的主要退出点
///
///存储库
///菜单的位置
///菜单的名称
///所选菜单项的名称
public void EA_MenuClick(EA.Repository Repository,string Location,string MenuName,string ItemName)
{
开关(项目名称)
{
//用户已单击菜单打开菜单选项
案例MENOOPEN:
这个;
打破
//用户已单击menuGoodbye菜单选项
//案例说明:
//这个。说再见();
//中断;
}
}
///
///向世界问好
///
私有void sayHello()
{
//MessageBox.Show(“MS.C项目”);
Form1.frmMain.ShowDialog();
this.OPEN_TOOL=true;
}
///
///向世界说再见
///
//私人空间
//{
//MessageBox.Show(“MS.C项目结束”);
//Form1.frm1.Hide();
//this.OPEN_TOOL=true;
//}
///
///EA在该操作存在时调用它。可用于执行一些清理工作。
///
公共无效EA_Disconnect()
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
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();
}
}
}