如何使用sql数据库设置良好的连接字符串app vb.net [英] how to set good connection string app vb.net with sql database

查看:120
本文介绍了如何使用sql数据库设置良好的连接字符串app vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我的应用程序由vb.net 2010编写的sql server数据库文件(mdf)我想分享这个应用程序,以便当用户点击图标应用程序工作并运行

我的连接字符串是

Hi I have app programed by vb.net 2010 with sql server database file (mdf) I want to share this app so that when user click on Icon app work and run
my connection string is

"Data Source=.\myservername;Initial Catalog=mydatabase name;Persist Security Info=True;User ID=sa;Password=mypass"



我的问题是:这个连接字符串是否正常工作。在我的电脑这项工作。我应该更改任何东西吗?


my question is that : is this connection string work or not . in my pc this work . should i change any thing ?

推荐答案

如果您的SQL实例被称为myservername为。,那将在您的机器上运行。表示本地计算机,因此.\myservername表示此计算机上名为myservername的SQL实例。它不适用于其他机器,因为代码会在他们的机器上而不是你的机器上查找SQL。数据源需要更新以使其他人看到您的计算机名称,或者如果您有固定的计算机,则需要更改IP地址。所以



数据源= machinename \instancename



如果没有调用SQL实例myservername 但你的意思是用你的机器名称替换myservername,那就不行了。如果您的SQL没有特定的实例名称,那么只需使用



data source = myservername



编辑:以上假设您希望将数据库保留在您的计算机上,而其他人将连接到它,如果不是这种情况更新您的问题以提供更多信息。
That will work on your machine if your SQL instance is called "myservername" as "." means your local machine so ".\myservername" means the SQL instance called "myservername" on this machine. It won't work on other machines as the code will look for SQL on their machine rather than yours. The datasource needs updated to have the name of your machine as seen by others, or your IP address if you have a fixed one. So

Data source=machinename\instancename

If the SQL instance isn't called "myservername" but you mean to replace myservername with the name of your machine, then that's not going to work. If your SQL has no specific instance name then just use

data source=myservername

The above assumes you are looking to keep the database on your machine and others will connect to it, if that's not the case update your question to supply more info.


这篇关于如何使用sql数据库设置良好的连接字符串app vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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