如何为使用sqlserver数据库的程序设置数据源 [英] how to set data source for program where use sqlserver database

查看:233
本文介绍了如何为使用sqlserver数据库的程序设置数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为安装和运行安装sqlserver的任何计算机上的程序设置数据源。

例如:@server = anfd-pc\SQLEXPRESS; database = Holoo1; Integrated Security = SSPI;



我应该使用什么服务器名称而不是anfd-pc \SQLEXPRESS?

因为计算机名称不同。

我用。和。\ SQLEXPRESS但不行。



我希望用户在textbox1.text中添加服务器和sqlserver名称,程序用这个名称连接到程序。

plz对我有帮助吗?

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 ?

推荐答案

你不能拥有一个可以与任何计算机一起工作的数据源 - 你需要解决具体问题承载数据库并连接到该数据库的SQL Server实例。它运行的PC的名称不仅可以不同,而且实例名称也不必是SQLEXPRESS。不同的安装也会有不同的登录,因此集成安全性可能并不总是SSPI。



如果用户输入服务器名称,那么只需构建适当的字符串 - 它只是从

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
string s = string.Format( "server={0};database = Holoo1; Integrated Security = SSPI", myTextBox.Text);

但您可能还需要不同的安全信息。

but you may need different security info as well.


这篇关于如何为使用sqlserver数据库的程序设置数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆