sql 2005连接字符串问题 [英] sql 2005 connection string problem

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

问题描述



我的硬盘上的ac#项目中有一个数据库,但是当我将项目移到另一台计算机上并且它的地址更改不起作用时,我认为它适用于以下代码:

Hi,

I have a data base in a c# project in my hard disk, but when i move my project to other computer and it''s address change , it doesn''t work , I think it''s for this code:

SqlConnection sqlconnection=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=G:\c#\LAS\LAS\mm.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");



有人可以帮我解决这个问题吗?



can anyone help me to solve this problem?

推荐答案

您已经硬编码了数据库的URL.
那不是最好的方法.您需要将数据库放置在中央服务器上,并允许所有客户端计算机指向该服务器.

如果它是本地数据库,请确保数据库始终位于您在此处指定的位置.
You have hardcoded the URL for the database.
That is not the best approach. You need to place your database on a central server and allow all client machines to point to that server.

If it is a local database, make sure the database is always in the location you have given here.


查看驱动器中是否有其他名称的文件.到目前为止,连接字符串说它在驱动器"G:\" 中.如果是这样的话,则进行适当的更改,并且应该可以正常工作
Look if you have your files in the drive with different name. As per now The connection string says it''s in drive "G:\". if so change is to appropriate one and it should work fine


不要对数据库的URL进行硬编码,而不是将其用作
Don''t hardcode the URL for the database, instead of that use it as
SqlConnection sqlconnection=new SqlConnection(@"Data Source=.\\SQLEXPRESS;database="Training";Integrated Security=True;Connect Timeout=30;User Instance=True");



希望这能解决您的问题.



Hope this will solve your problem.


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

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