<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Connect to SQL database from C# plugin in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7301694#M30153</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/587082"&gt;@hgasty1001&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you need to create the connection *inside* your application. I usually create a class with all the db business needed to connect, retrieve data and so on. It's very simple to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This (because I can only give one kudo).&amp;nbsp; If there is some concern about having to change database at a later point&amp;nbsp;(e.g. supporting multiple clients, systems migration), you can always store the variable information in a registry or data file if you don't want to handle that inside the program as well.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2017 14:39:31 GMT</pubDate>
    <dc:creator>dgorsman</dc:creator>
    <dc:date>2017-08-15T14:39:31Z</dc:date>
    <item>
      <title>Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7295765#M30146</link>
      <description>&lt;P&gt;I am developing a C# AutoCAD plugin that needs to connect to SQL database to save and retrieve data from it.&lt;/P&gt;&lt;P&gt;when i tried to use the database from the plugin i got this error "&lt;EM&gt;&lt;STRONG&gt;No connection string named '&lt;/STRONG&gt;&lt;/EM&gt;QSurvEntities'&lt;EM&gt;&lt;STRONG&gt; could be found in the application config file&lt;/STRONG&gt;&lt;/EM&gt;".&lt;/P&gt;&lt;P&gt;I tried to connect to the database through&amp;nbsp;DBCONNECT but i got the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I&amp;nbsp;add the following connection string in AutoCAD configuration file using AutoCAD API ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;connectionStrings&amp;gt;&lt;BR /&gt;&amp;lt;add name="QsurvEntities" connectionString="metadata=res://*/QsurveEntityModel.csdl|res://*/QsurveEntityModel.ssdl|res://*/QsurveEntityModel.msl;provider=System.Data.SqlClient;provider connection string=&amp;amp;quot;Data Source=.;Initial Catalog=Qsurv;Integrated Security=True;App=EntityFramework&amp;amp;quot;" providerName="System.Data.EntityClient"/&amp;gt;&lt;BR /&gt;&amp;lt;/connectionStrings&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2017 07:31:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7295765#M30146</guid>
      <dc:creator>ahmedshawkey95</dc:creator>
      <dc:date>2017-08-12T07:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7296929#M30147</link>
      <description>&lt;P&gt;Do you want to connect to AutoCAD built-in DBConnect (via COM API CAO 1.0), or as a general data connection to a database server, such as SQL server. They are 2 different things, in terms of AutoCAD programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The former is a special data connection built into AutoCAD. It can be programmatically manipulated through special API CAO1.0, which is COM API. This type of data connection is only used with AutoCAD built-in data-linked template/label.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more generic data manipulation from AutoCAD (retrieving/updating data from/to database, such as SQL Server), with .NET platform, you can use ADO.NET to directly connect to database and do whatever you need/could do. In these days, it would be more often to have AutoCAD connect to services to retrieve/update data indirectly from/to database, rather than direct connect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To give more detailed/specific suggestion, you may want to provide more description of your case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you indeed want to connect to AutoCAD built-in DBConnect, then you need to add refernce to CAO 10. library. And you need to setup a datasource in AutoCAD (which you already have, according to the picture you attached). Then you simply create a DBConnec object and call Connect() method. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim cn As New CAO.DbConnect()&lt;/P&gt;
&lt;P&gt;cn.Connect("TheDataSourceName")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2017 13:20:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7296929#M30147</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-08-13T13:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297023#M30148</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;I don't want to use &lt;SPAN&gt;built-in DBConnect. Instead,&amp;nbsp;&lt;/SPAN&gt;I want to connect my&amp;nbsp;AutoCAD plugin to the database through Entity Framework.&lt;/P&gt;&lt;P&gt;but when I tried to retrieve data using the Database Entity Model in my Plugin, I got the mentioned&amp;nbsp;error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2017 15:31:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297023#M30148</guid>
      <dc:creator>ahmedshawkey95</dc:creator>
      <dc:date>2017-08-13T15:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297155#M30149</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3631736"&gt;@ahmedshawkey95&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;...Can I&amp;nbsp;add the following connection string in AutoCAD configuration file using AutoCAD API ?...&lt;/P&gt;
&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No! Moreover acad.exe.config usually protected from modification if user is not in Administrator (Local Administrator) group.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Aug 2017 17:45:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297155#M30149</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2017-08-13T17:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297636#M30150</link>
      <description>&lt;P&gt;hi there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is it possible to start up a hello world console application and to try to connect to the database using entity frameworks without including the autocad plugin. if you are not careful when instantiating the db context you could have some trouble. try hard coding the string at first, and then once you have that working then try getting it dynamically. i have included the comments which might help you understand where you could possibly be going wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is some code which worked for me when hardcoded. i had tried to dynamically get the connection string, but am not sure how successful i was with it. it has been some time since i used entity frameworks on my desktop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    [DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class PanelContext : DbContext
    {
        // Your context has been configured to use a 'PanelContext' connection string from your application's 
        // configuration file (App.config or Web.config). By default, this connection string targets the 
        // 'localMysqlPanelTest.PanelContext' database on your LocalDb instance. 
        // 
        // If you wish to target a different database and/or database provider, modify the 'PanelContext' 
        // connection string in the application configuration file.
        
        //// This was the old constructor
        //public PanelContext() : base("name=PanelContext")
        
        // connection string is hard coded
        public PanelContext() : base("server=localhost;port=3306;database=PanelContext;uid=TYPEUSERNAMEHERE;password=LUCKYICHECKEDTHISBEFOREPOSTINGTOTHEFORUM😊")         
        {            
        }

        private void GetConnectionString()
        {
            //SettingsPropertyCollection test = localMysqlPanelTest.Properties.Settings.Default.Properties;
            //ConnectionStringSettingsCollection cs = ConfigurationManager.ConnectionStrings;
            //string connectionString = ConfigurationManager.AppSettings["PanelContext"];

            // var connection = new ConnectionFactory().GetConnection(ConfigurationManager.ConnectionStrings["PanelContext"].ConnectionString, DataBaseProvider);
            //var connection = System.Configuration.ConfigurationManager.ConnectionStrings["PanelContext"].ConnectionString;

            //string connectionString = ConfigurationManager.ConnectionStrings["PanelContext"].ConnectionString;
            //ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
            //configFileMap.ExeConfigFilename = roamingConfig.FilePath;

            //// Get the mapped configuration file.
            //Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            
        }

        public DbSet&amp;lt;Panel&amp;gt; Panels { get; set; }

        public DbSet&amp;lt;Block&amp;gt; Blocks { get; set; }   

        // Add a DbSet for each entity type that you want to include in your model. For more information 
        // on configuring and using a Code First model, see http://go.microsoft.com/fwlink/?LinkId=390109.

        // public virtual DbSet&amp;lt;MyEntity&amp;gt; MyEntities { get; set; }
    }
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2017 04:17:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7297636#M30150</guid>
      <dc:creator>BKSpurgeon</dc:creator>
      <dc:date>2017-08-14T04:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7299875#M30151</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you need to create the connection *inside* your application. I usually create a class with all the db business needed to connect, retrieve data and so on. It's very simple to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2017 20:28:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7299875#M30151</guid>
      <dc:creator>hgasty1001</dc:creator>
      <dc:date>2017-08-14T20:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7301676#M30152</link>
      <description>&lt;P&gt;When you use Entity Framework, if you let VisualStudio does the work, it adds its connection information in app.config. If your application is EXE, or a web app, then you do not have to bother too much with how to get the connection info from config file. However, you are doing DLL as Acad add-in, Acad as EXE app, it gets configuration from acad.exe.config. So, you either need to merge the connection string section in the DLL's app.config into acad.exe.config, or let your code to somehow load the settings from the DLL's app.config (which would be built as *.dll.config). Search the net for how to use *.config with DLL. You may also want to learn/try how to pass Entity Framework's DBConext connection information without relying on VS created configuration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 14:34:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7301676#M30152</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-08-15T14:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7301694#M30153</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/587082"&gt;@hgasty1001&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you need to create the connection *inside* your application. I usually create a class with all the db business needed to connect, retrieve data and so on. It's very simple to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gaston Nunez&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This (because I can only give one kudo).&amp;nbsp; If there is some concern about having to change database at a later point&amp;nbsp;(e.g. supporting multiple clients, systems migration), you can always store the variable information in a registry or data file if you don't want to handle that inside the program as well.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 14:39:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7301694#M30153</guid>
      <dc:creator>dgorsman</dc:creator>
      <dc:date>2017-08-15T14:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7654623#M30154</link>
      <description>&lt;P&gt;Have you founded the connection??&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2017 19:16:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7654623#M30154</guid>
      <dc:creator>alvaro_gt1</dc:creator>
      <dc:date>2017-12-29T19:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Connect to SQL database from C# plugin</title>
      <link>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7655575#M30155</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;gave the answer. you can create / use&amp;nbsp; yourapp.dll.config as long as it's installed in the same folder as your dll.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/594298/c-sharp-dll-config-file" target="_blank"&gt;https://stackoverflow.com/questions/594298/c-sharp-dll-config-file&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Dec 2017 17:47:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/connect-to-sql-database-from-c-plugin/m-p/7655575#M30155</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2017-12-30T17:47:21Z</dc:date>
    </item>
  </channel>
</rss>

