.NET数据库连接 [英] .NET database connectivity

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

问题描述

我当前正在使用MS-Visual Studio .NET.但是我面临着数据库连接性的问题(即当我想通过与SQL Server集成在一起的SQL Server创建任何新数据库时,会引发有关连接性的错误.

I''m currently using MS-Visual Studio .NET. But I was facing a problem of database connectivity (i.e when I want to create any new database through the SQL Server integreted with the soft it throws an error about connectivity.

我正在使用Avast Antivirus.有人可以帮我吗?

I am using Avast Antivirus. Can anyone please help me out?

推荐答案

嘿?

Hey ?

有两种方法可以连接到任何数据库.

There are 2 ways to connect to any database.


  1. 连接的建筑
  2. 断开连接的架构

  1. Connected Architecure
  2. Disconnected Architecture





//Connected Architecure
  
Add namespace
Using System.Data.SqlClient;

SqlConnection con=new SqlConnection(@"Server="U R COMPUTER NAME\SQLEXPREES"; uid=""; password="" );

// or u hav 2 specify u r server name 
SqlConnection con=new SqlConnection(@"Server="U R COMPUTER NAME\SQLEXPREES";IntegratedSecurity="SSPI" );

con.open();
SqlCommand cmd=new SqlCommand("Select * from table name",con);

SqlDataReader=cmd.ExeuteReader();


GridView1.DataSource=dr;

//or u may traverse through it
while(dr.read())
{
  // u r code. u can access coloumn by dr[0].ToString(); and so on;
}

//finally close the connection

con.close();




非常简单,请为我的回答打分.




so simple please rate my answer THANKS.


嘿,
您遇到什么类型的错误?

我建议在开始编程之前先阅读基础知识.
:)
Hey,
What type of error you are getting?

I recommend to read the basics first before starting programming.
:)


如果您需要有关错误消息的帮助,请发布ACTUAL消息,而不是您对它的解释.

如果通过SQL Server实例创建数据库,则需要获取连接字符串以指向该数据库,它将正常工作.如果您认为反病毒是一个问题,请将其关闭以查看.这样一来,您就可以确定并解决问题,或者停止吠错树.
If you need help about an error message, post the ACTUAL message, not your interpretation of it.

If you create a database through a SQL Server instance, then you need to get your connection string to point to that database and it will work fine. If you think the anti virus is an issue, turn it off to see. That way you can know for sure and either work on the problem, or stop barking up the wrong tree.


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

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