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
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" ;
public string strConnectionstring = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\DataBaseName.mdf";
<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.
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;" />
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/
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