Sql connection-string for localhost server

前端 未结 13 2026
遇见更好的自我
遇见更好的自我 2020-12-09 01:28

I am newbie in this .NET and please don\'t mind in answering my simple question. I am trying to write a windows application, where in I am using a localhost SQLserver for da

相关标签:
13条回答
  • 2020-12-09 01:47

    When using SQL Express, you need to specify \SQLExpress instance in your connection string:

    string str = "Data Source=HARIHARAN-PC\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True" ;
    
    0 讨论(0)
  • 2020-12-09 01:48
    public string strConnectionstring = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\DataBaseName.mdf";
    
    0 讨论(0)
  • 2020-12-09 01:49
    <add name="connstr" connectionString="Data Source=localhost;Initial Catalog=DBName;User Id=username;Password=password" providerName="System.Data.SqlClient"/>
    

    The above also works. It ignores the username and password passed in in the connection string. I switched from an environment db to a local one, and it works fine even though my user in the connection string does not exist in this context.

    0 讨论(0)
  • 2020-12-09 01:50

    Using the default instance (i.e., MSSQLSERVER, use the DOT (.))

    <add name="CONNECTION_STRING_NAME" connectionString="Data Source=.;Initial Catalog=DATABASE_NAME;Integrated Security=True;" />
    
    0 讨论(0)
  • 2020-12-09 02:01

    In .Net configuration I would use something like:

    "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=..."
    

    This information is from https://www.connectionstrings.com/sql-server-2016/

    0 讨论(0)
  • 2020-12-09 02:01
    Data Source=HARIHARAN-PC\SQLEXPRESS; Initial Catalog=Your_DataBase_name; Integrated Security=true/false; User ID=your_Username;Password=your_Password;
    

    To know more about connection string Click here

    0 讨论(0)
提交回复
热议问题