HI it's not good to hard code connection string you can save it in the configuration file or in the regsitery and the connection string must be encrypt.
but to do simple i will show you the easy way to achieve your need.
: when you put Integrated Security=True
in your connection string your code will work naturally on the computer where the database is install because Integrated Security=True
mean that you use the Windows authentification which (the current user is add to sqlserver users by default at installation.)
but when you go on other computer you can continue to use Integrated Security=True
, but you must add each Windows user on those computer to the instance of your sqlserver. it's better for security
so do to simple you can create a super admin user in your sqlserver instance and use the unique credentials on others computer like this
CREATE LOGIN [sa] WITH PASSWORD=N'pwd', DEFAULT_DATABASE=[databasename] CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
EXEC sys.sp_addsrvrolemember @loginame = N'sa', @rolename = N'sysadmin'
Or you can use sqlmanagement to do this with the designer : go to the instance security node and in the connexion node so you can create the superadmin user
now the connection string should be (it can work on any pc in the network. don't forget to allow distance connection on the sqlserver instance and Add sqlserve in windows firewall exception)
SqlConnection con = new SqlConnection("Data Source=abhijeet-PC\\SQLEXPRESS;Initial Catalog=inventory_test;User Id=sa;Password=pwd");