Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SqlConnection con = new SqlConnection("Data Source=abhijeet-PC\\SQLEXPRESS;Initial Catalog=inventory_test;Integrated Security=True");


i have seted the connection string to this

now i am creating exe of this project but this exe not working properly on
other computer shows error on connecting database.

how to integrate the database to the exe that it can run on each computer
i am using sql server 2008 r2 and visual studio 2010
Posted

You can't write a single connection string that will work on any PC.
There is no law that says that all SQL Server instances must be on a particular PC, or have a particular instance name, much less that the login must be Windows user based instead of individual username and password combinations.

The best you can do is to use a configuration file of some form, and read your connection string from that.
Exactly what kind of config file, and how you access it will depend on you and you application environment.
 
Share this answer
 
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.

Advice : 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

SQL
CREATE LOGIN [sa] WITH PASSWORD=N'pwd', DEFAULT_DATABASE=[databasename] CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
GO

EXEC sys.sp_addsrvrolemember @loginame = N'sa', @rolename = N'sysadmin'
GO


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)

SQL
SqlConnection con = new SqlConnection("Data Source=abhijeet-PC\\SQLEXPRESS;Initial Catalog=inventory_test;User Id=sa;Password=pwd");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900