VC#和SQL数据库连接查询 [英] VC# and SQL database connection query

查看:112
本文介绍了VC#和SQL数据库连接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是MCA学生,我对.net技术非常感兴趣。为了获得有关这些技术的更多知识,我正在使用VC#,SQL和ADO.net进行一些实验。



我正在尝试访问数据库。我有两台电脑,我已经从LAN电缆连接这些电脑。我已经在我的笔记本电脑和其他计算机上安装了SQL Server 2005,我已经创建了一个基本程序。



现在我的目标是将测试表中存储的数据存储到另一台计算机上。



i尝试过以下连接字符串,但它不起作用:



Hello everyone,

I am a MCA student and i have huge interest in .net technologies. To get more knowledge about these technologies i was doing some experimentation with VC#, SQL and ADO.net.

i am trying to access the database. i have two computers, i have connected these computers from LAN cable. i have installed the SQL server 2005 in my laptop and in other computer i have created a basic program.

now my objective is to get the data stored in the test table to my another computer.

i have tried below connection string but it wont worked:

SqlConnection con= new SqlConnection();
con.connectionstring="data source=Jhon-PC; initial catalog=jhon; uid=sa; pwd= test";
con.open();
String query="select * from test";





问题是相同的代码在数据库和程序相同时工作正常电脑,我无法理解原因。


也想告诉你我正试图在网格视图中访问这些信息。



i想要了解我是否需要在我的笔记本电脑上安装一些软件,我已经存储了我的数据库。或者还有其他方法可以完成这项任务..



感谢您的帮助。



problem is same code works perfectly when database and program is on same computer, i am not able to understand the reason.

also like to inform you that i am trying to access the information in a grid view.

i want to understand that do i need to install some software on my laptop on which i have stored my database. or there is some other way to do this task..

Thanks for your help.

推荐答案

连接字符串中的数据源是指安装了Sql Server的计算机。如果指定正确的macine名称,客户端应用程序将尝试连接到已安装的Sql Server的默认实例(如果有默认实例)



另一种类型的实例是一个命名实例。主要区别在于,只能使用计算机名(或IP地址)来连接命名的intance。使用命名实例,您必须指定bopth macine和Sql Server实例的名称。



另一件事是当您连接到本地计算机外部的Sql Server时,你必须能够使用适当的端口进行通信。如果计算机之间存在防火墙,则必须打开用于建立连接的端口。当使用Sql Server的默认设置时,默认端口是1433.



如其他成员已经提到的,您可以检查http://www.connectionstrings.com/sql-server-2005 [ ^ ]
The data source in your connection string refers to the machine Sql Server is installed on. If you specify correct macine name, the client application tries to connect to the default instance of installed Sql Server (if there''s a default instance)

Another type of instance is a named instance. The main difference is that a named intance cannot be connected to by using only computer name (or IP address alternatively). With named instance you have to specify bopth macine and the name of the instance of Sql Server.

Another thing is that when you connect to a Sql Server outside the local computer, you have to be able to communicate using proper ports. If there are firewalls in between the computers, a port to establish the connection must be opened. When using default setting with Sql Server the default port is 1433.

As already mentioned by another member, you can check the full syntax from http://www.connectionstrings.com/sql-server-2005[^]


这篇关于VC#和SQL数据库连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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