Click here to Skip to main content
15,921,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want set data source for program where install and run on any computer where have install sqlserver.
for example : @"server=anfd-pc\SQLEXPRESS;database = Holoo1; Integrated Security = SSPI";

I should use what server name instead anfd-pc\SQLEXPRESS ?
bacause computer name is different .
I use . and .\SQLEXPRESS but not work.

I want user add server and sqlserver name in textbox1.text and program connect with this name to program.
plz help to me ?
Posted
Updated 3-May-13 4:38am
v2

1 solution

You can't have a single datasource that will "work with any computer" - you need to address the specific instance of SQL server that hosts your database, and connect to that. Not only can the name of the PC it runs on be different, but the instance name does not have to be SQLEXPRESS either. Different installations will have different logins as well, so "Integrated Security" may not always be "SSPI".

If the user enters a server name, then just build the appropriate string from that - it's just a case of creating a formatted string from
C#
string s = string.Format( "server={0};database = Holoo1; Integrated Security = SSPI", myTextBox.Text);
but you may need different security info as well.
 
Share this answer
 
Comments
zxo004 3-May-13 10:42am    
what security info is better for this ?
OriginalGriff 3-May-13 11:00am    
It's not a case of "better" or "worse" - it's now the installation of SQL Server you want to connect to is configured. Some require a "proper" login, rather than the default Windows ID login.

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