无法连接数据库 [英] Unable to connect database

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

问题描述

我创建了一个登录表单,但无法连接数据库。它显示以下错误



实例失败。

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。



异常详细信息:System.InvalidOperationException:实例失败。



来源错误:





第27行:cmd.Parameters.AddWithValue(@ UserName,txtUserName.Text);

第28行:cmd .Parameters.AddWithValue(@ Password,txtPWD.Text);

第29行:con.Open();

第30行:SqlDataAdapter da = new SqlDataAdapter(cmd );

第31行:DataTable dt = new DataTable();

i created a login form but not able to connect the database.It shows the below error

Instance failure.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Instance failure.

Source Error:


Line 27: cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
Line 28: cmd.Parameters.AddWithValue("@Password", txtPWD.Text);
Line 29: con.Open();
Line 30: SqlDataAdapter da = new SqlDataAdapter(cmd);
Line 31: DataTable dt = new DataTable();

推荐答案

检查您的实例是否正常工作。

尝试使用这些步骤连接sql server

数据库连接使用Visual Studio的Oracle,SQL Server和MS Access



如果连接成功,则在执行以下步骤后使用相同的连接字符串。
Check your instance is working.
try to connect sql server with these steps
Database connectivity with Oracle,SQL Server and MS Access using Visual Studio

if it connected successfully then use same connection string careted after following given steps.


第29行:co n.Open();

第27行:cmd.Parameters.AddWithValue(@ UserName,txtUserName.Text);

第28行:cmd.Parameters.AddWithValue( @Password,txtPWD.Text);

第30行:SqlDataAdapter da = new SqlDataAdapter(cmd);

第31行:DataTable dt = new DataTable();



试试这个..你需要先打开连接
Line 29: con.Open();
Line 27: cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
Line 28: cmd.Parameters.AddWithValue("@Password", txtPWD.Text);
Line 30: SqlDataAdapter da = new SqlDataAdapter(cmd);
Line 31: DataTable dt = new DataTable();

Try this..You need to open connection firstly


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

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