简体   繁体   中英

Can't connect to local SQL database with connection string ,'Form1' does not contain a definition for 'Properties'

I am trying to connect my local SQL database to ac# forms application but it won't read data from the file.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        string connectionString = Form1.Properties.Settings.Default.ConnectionString;
    }
}

Normally your Settings class should be under <DefaultProjectNameSpace>.Properties.Settings.Default.ConnectionString where <DefaultProjectNameSpace> is the namespace of your project/application.

If it is not there try to locate it from your project under the Properties folder.

 <connectionStrings>
    <add name="MediaMantradb" connectionString="data source=.;database=MediaMantradb; integrated security=true; trusted_connection=true" providerName="System.Data.SqlClient"/>
 </connectionStrings>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM