UserControl related problem with Form designer as i call methods from a Class C#

0

1- I have added a SQLite connection string in app.config, and when i call it, an error appears in the form designer (Object reference not set to an instance of an object) Designer error image

2- I tried to get the connection string by index number, a different error appears in designer (Unable to load DLL 'SQLite.Interop.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) ) Designer error image

App.config:

<connectionStrings>
    <add 
           name="Cons" 
           connectionString="Data Source=|DataDirectory|PT.db; Version=3;" 
           providerName="System.Data.Sqlite"
     />
</connectionStrings>

in class call:

public class SQL
    {
        private static SQLiteConnection con = new SQLiteConnection(ConfigurationManager.ConnectionStrings["Cons"].ConnectionString);

        public static void Open()
        {
            con.Open();
        }
    }

[Update]

I found this problem presents when i call any method from SQL class in ControlTime UserControl as this code

public partial class ControlTime : UserControl
    {
        public ControlTime()
        {
            InitializeComponent();
            SQL.Open(); // if i remove this line the error disappears 
        }
    }

What can i do to call SQL Class with out any error in the Form designer?

c#
sqlite
system.data.sqlite
asked on Stack Overflow Mar 25, 2019 by Mohamed Wagih • edited Mar 25, 2019 by Mohamed Wagih

1 Answer

0

Try this Connectionstring:

<connectionStrings>
    <add name="Cons" 
    connectionString="data source=.\PT.sqlite"
    providerName="System.Data.SQLite"/> 
</connectionStrings> 
answered on Stack Overflow Mar 25, 2019 by Halil Şahin • edited Mar 25, 2019 by Halil Şahin

User contributions licensed under CC BY-SA 3.0