下面的代码错在哪里?为什么总是连接失败??
各位大虾帮帮忙啊!感激不尽!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;namespace WebApplication7
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, System.EventArgs e)
{
try
{
SqlConnection myConnection = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=;database=Aspnet";
myConnection.ConnectionString = strConn;
myConnection.Open();
Response.Write("连接成功!");
myConnection.Close();
} catch
{
Response.Write("连接失败!");
}
}
}
}
各位大虾帮帮忙啊!感激不尽!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;namespace WebApplication7
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, System.EventArgs e)
{
try
{
SqlConnection myConnection = new SqlConnection();
string strConn = "server=localhost;uid=sa;pwd=;database=Aspnet";
myConnection.ConnectionString = strConn;
myConnection.Open();
Response.Write("连接成功!");
myConnection.Close();
} catch
{
Response.Write("连接失败!");
}
}
}
}
解决方案 »
- C# 导出 Excel 单元格选中内容上颜色
- VisualStudio2010中,怎么添加对System.ServiceModel的引用?
- 水晶报表的合计问题
- ReDim BaseData(30, 3) As String是什么意思?(抢分贴)
- C#如何实现查出Access数据库共多少条记录
- 怎样才能屏蔽掉RichTextBox的Ctrl+鼠标Wheel缩放功能?
- 现金求购买圈子程序与个性化定制
- 有没有用Windows Workflow的?问一个Workflow Service的问题
- 在Web上,关连表绑定数据源到DataGrid
- 请问怎样把“050D55”这个字符串转换为16进制的,救急
- 请问哪个版本的svn好用.
- 【急】vs2005下gridview的问题,高手进
越答越错,没有 server=(localhost) 这种写法的。应该是:server=.
server=127.0.0.1
server=(local)
server=localhost之一。
string strConn = @"server=localhost\SQLPRESS;uid=sa;pwd=;database=Aspnet";
string strConn = "server=localhost\\SQLPRESS;uid=sa;pwd=;database=Aspnet";
server=.
server=127.0.0.1
请确认你自己本地装的sql服务器名,用户,密码
数据库是否存在, 是不是你建立的,不是的话有没有附加数据库.
你那代码是vs2005里是能正常运行的.你的是2008,我想这和版本没有影响.
请加这些代码测下.
catch(Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}