连接字符串不起作用. [英] Connectionstring doesn't work.

查看:103
本文介绍了连接字符串不起作用.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在自己的计算机上创建了一个应用程序,并且在创建时根本没有问题.

我在本地计算机上运行了此连接字符串,并且运行良好.

I have made an application on my own computer, and at the time of creation there were no problems at all.

I runned this connection string on my local computer, and it worked perfectly.

private SqlConnection connection = new SqlConnection("Data Source=LT004512\\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=SSPI;");



但是,当我将连接字符串编辑为以下内容(因为它必须在另一台计算机上运行)时,我的程序无法启动.



However, when i edited the connection string to the following (becouse it had to run on an other computer), my program didn''t start.

private SqlConnection connection = new SqlConnection("Data Source=VG-VJGZTEST\\SQLEXPRESS;Initial Catalog=databasename;Integrated Security=SSPI;");



起初我认为没什么大不了的,但是它在客户端服务器上也不起作用.

由于某种原因,它只能在本地主机上工作,并且看起来无法建立连接.

有谁知道我必须采取什么措施来解决此问题.



No big deal i thought at first, but it also didn''t work at the cliënt server.

For some reason, it only worked at the local host, and it looks like it can''t get a connection.

Does anyone know what steps i have to take to counter this problem.

推荐答案

我猜您尚未在SQL Server网络配置中启用TCP/IP在服务器上.

使用Microsoft SQL Server 2008找到SQL Server网络配置->配置工具-> Sql Server配置管理器
I''m guessing you haven''t enabled TCP/IP in SQL Server Network Configuration on the server.

SQL Server Network Configuration is found using Microsoft SQL Server 2008 -> Configuration Tools -> Sql Server Configuration Manager


队友,
如你所说,它应该可以正常工作..
可能是其他计算机的数据库中存在此问题..
再次正确检查..
它一定会工作..
如果它在您的本地计算机上正常工作..
应该有一些手动错误..
hey mate,
as u said it should work properly..
may be the problem is in other computer''s database..
check it once again properly..
it will definately work..
if it work''d properly on your local computer..
there should be some manual error..


在您的情况下,请尝试使用IP地址-应该可以.

在数据源中硬编码计算机名称/IP地址永远不是一个好主意.
这应该可以通过配置文件或其他东西进行配置.
原因是您不想在每次数据库服务器更改时都编译代码.
In your case, try using the IP address - that should work.

It is never a good idea to hard code the computer name / ip address in your datasource.
This should be configurable via a config file or something.
The reason is that you dont want to compile your code every time the database server changes.


这篇关于连接字符串不起作用.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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