如何从本地计算机连接数据库服务器? [英] How to connect database server from my local Machine?

查看:94
本文介绍了如何从本地计算机连接数据库服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用.net中的连接方法更新本地机器数据库。

现在我想更新服务器端数据库(本地机器中的同一个表)通过使用相同的程序..

i知道服务器数据库用户名,数据库名称,密码,表名..

请有人帮我解决这个问题....我该怎么办?跟进连接.......

Hi,
am updating local machine database by using connection method in .net..
now i want to update server side database(same table in local machine) by using same program..
i know the server database username,database name,password,table name ..
please anyone help me regarding this....how should i follow in connection .......

推荐答案

首先在web.config / app.config中设置连接字符串



然后从那里读取connectionstring

sqlconnection con = new sqlconnection(来自config的connectionstring)
First set connectionstring in web.config/app.config

Then read connectionstring from there
sqlconnection con=new sqlconnection(connectionstring from config)


你好Kumar,



如果你有多个开发区域(DEV,UAT,PROD),那么在web.config中存储连接字符串是一个很好的做法。

这对你来说会更容易读取连接字符串并在代码隐藏文件后建立连接。



在Web.config文件中找到connnectionstring部分并重新以下代码的地方



Hi Kumar,

If you have more than one region for development(DEV,UAT,PROD) its a good practise to store connection string in web.config.
Which will be easier for you to read the connection string and establish the connection in code behind file.

In Web.config file find connnectionstring section and replace with below code

<connectionStrings>
<add name="localConnectionString" connectionString="SERVER=.\SQL2008;DataBase=StudentDatabase;UID=rk.prabakar;pwd=*****;" providerName="System.Data.SqlClient"/>
<add name="serverConnectionString" connectionString="Server=server\SQL2008;Database=StudentServerDatabase;User ID=sa;Password=*******;providerName="System.Data.SqlClient"/>
</connectionStrings>





在服务器端代码中,



In server side code,

con = new SqlConnection(ConfigurationManager.ConnectionStrings["localConnectionString"].ToString()); //Points to local database connection string
or
con = new SqlConnection(ConfigurationManager.ConnectionStrings["serverConnectionString"].ToString()); //Points to server database connection string



完成数据库后,可以建立连接,如con.open();



您开始执行命令。

因此连接到服务器数据库完全取决于连接字符串。



问候,

RK


Once you finalized with database, you can establish the connection like con.open();

And you start executing your command.
So connecting to server database is solely depends on the connection string.

Regards,
RK


这篇关于如何从本地计算机连接数据库服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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