从.NET应用程序与放大器的变化数据源动态;传递给接法串数据源、放大器、应用程序、动态

2023-09-06 22:39:48 作者:人间悲欢客

我的Visual Studio .NET应用程序使用SQL Server 2005前preSS。

My Visual Studio .NET application uses SQL Server 2005 Express.

它必须在我的客户的主服务器的系统和放大器安装;在两个客户端computers.all与Windows XP或Vista或Windows 7。

It has to be installed on my customer's main server system & on two client computers.all with Windows XP or Vista or 7.

现在,每一次当我安装我的应用程序和放大器;在我的客户计算机上的SQL Server,我必须要改变的连接字符串中指定的服务器名,即数据源。 因为,当我客户的计算机上安装SQL Server,那么服务器名称采取的是SQL Server 2005的防爆preSS,作为客户的计算机名称。

Now, every time when i install my application & SQL Server on my customers computers, I have to change the server name specified in the connection string, i.e. the DATA SOURCE. Because, when I install SQL Server on customer's computer, then the server name is taken by SQL Server 2005 Express, as the computer name of the customer.

那么,有什么解决方案呢?

So, what's the solution for this?

要我改变客户的计算机名称,什么我在连接字符串中指定。 或者,我应该动态地把服务器名称从.NET应用程序运行时,然后将其传递给连接字符串。

另外,同样的问题是用于登录?我的.NET应用程序会要求登录和放大器;密码从客户,这将被传递到连接串安培;应用程序将连接到SQL Server。所以,这是正常的安全?如果没有,那么有什么其他的解决办法,从.NET应用程序动态创建的SQL Server登录。

Also, the same problem is for login? My .NET application would ask for the login & password from the customer, which would then be passed to the connection string & the application would connect to SQL Server. So, is this ok with security? if not, then what's the other solution to create logins of SQL Server from the .NET application dynamically.

另外,我应该创建应用程序角色,为了这个目的,即解决登录问题?

Also, should i create APPLICATION ROLES for this purpose , i.e. for solving the login problem?

我的连接字符串是:数据源= A-9(计算机名); Trusted_Connection = TRUE;

My connection string is : Data Source = A-9 (computer name) ; Trusted_Connection = true;

---------------------------------------------- EDITED ---------------------------------------

----------------------------------------------EDITED---------------------------------------

目前我客户的地方,APP_SVR'是服务器的机器名,他有2个客户端 M / CS:C-1和; C-2。所有3都在局域网简单的家用PC,与Windows XP。

At my customer's place,'APP_SVR' is server machine name, he has 2 client m/cs : C-1 & C-2. All 3 are simple home PCs on LAN, with Windows XP.

1.我会在'APP_SVR安装SQL Server EX $ P $干燥综合征。虽然安装,   SQL Server自动接受服务器名称作为计算机名   在其上安装的,在这里它是APP_SVR'。   因此,APP_SVR将在康涅狄格州的数据源名称。字符串。

1.I will install SQL SERVER EXPRESS on 'APP_SVR'. While installation, SQL SERVER automatically takes the server name as the computer name on which it is installed , here it is 'APP_SVR'. So , 'APP_SVR' will be the DATA SOURCE NAME in the conn. string.

2。我将安装在C-1,C-2。

2.I will install the .NET application on C-1,C-2.

3.Now,在C-1的应用,C-2将要连接到SQL Server上的APP_SVR。   对于这一点,applcn。需要数据源名称。因此,我想借此从数据源名称   用户可以使用C-1和; C-2,作为文本输入和放大器;然后将它传递给连接字符串。   该用户将其输入为APP_SVR。

3.Now, the application on C-1,C-2 will have to connect to SQL SERVER on 'APP_SVR'. For this,the applcn. needs DATA SOURCE NAME. So, I would take the data source name from users using C-1 & C-2, as a text input & then pass it to the connection string. The users would enter it as 'APP_SVR'.

这将是罚款与安全问题?或者是有什么其他的办法吗?

Would this be fine with security issues ? or is there any other way?

推荐答案

至于连接字符串参与,oleschri是正确的。你最好的选择是使用一个app.config文件。然后,您将不得不更改连接字符串用手指向正确的服务器。有动态使这个你有没有办法知道在服务器计算机的IP /名字从客户端到客户端,直到看到环境中没有真正的方法。

As far as the connection string is involved, oleschri is correct. Your best option is to make use of an app.config file. You will then have to change the connection string to point to the correct server by hand. There is no real way of making this dynamically as you have no way of knowing the ip/name of the server machine from client to client until you see the environment.

至于登录和连接应用到SQL,这是可以做到你的建议的方式。与动态地改变所述连接字符串与由用户提供的用户名和密码。

As for the logins and connecting the application to SQL, this can be done the way you are suggesting. With changing the connection string dynamically with the username and password provided by a user.

一般,我处理这个问题在我的数据库中创建一个用户表。此表将具有用户名和密码,以允许访问我的程序。在SQL Server的登录名应该使用的限制/安全访问数据库本身。我一般创建一个登录名/用户,所有用户,然后使用这个来访问数据库。这有助于获得锁定到数据库,同时允许您提供安全访问应用程序。对于这个工作,虽然,你将需要采取的用户名/密码,从用户和检查数据库,看它是否存在并且是正确的。如果是的话让他们继续下去,如果不是让他们在登录屏幕上,并告诉他们,无论是用户名和/或密码是错误的。

Generally, I handle this by creating a users table in my database. This table would have usernames and password to allow access to my program. The logins in SQL Server should be used for limiting/securing access to the database itself. I generally create one login/user and all users then use this to access the database. This helps to lock down access to the database while allowing you to provide security to access the application. For this to work though, you will need to take the username/password from the user and check the database to see if it exists and is correct. If so let them continue, if not keep them at the login screen and tell them that either the username and/or password is wrong.