嘿,我收到打开错误,请为我解决 [英] hey im getting the error of open please solve it for me

查看:46
本文介绍了嘿,我收到打开错误,请为我解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class SignUp : System.Web.UI.Page
{
    DateTime dt;
    SqlCommand cmd;
    SqlConnection cn;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        cn = new SqlConnection(ConfigurationManager.AppSettings["cn"]);
        cn.Open();===>this was error it was giving
        
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        SqlDataReader dr;


    

    
        cmd = new SqlCommand("Select * From Registration where uname = '" + txt_uname.Text + "' or email = '" + txt_email.Text + "'", cn);
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            lblerr.Text = "User Already Exists Try Again.";
        }
        else
        {
            dr.Close();
            string qu = "INSERT INTO Registration values ('" + txt_uname.Text + "','" + txt_pass.Text + "','" + txt_fname.Text + "','" + txt_mname.Text + "','" + txt_lname.Text + "','" + txt_address.Text + "','" + txt_email.Text + "','" + drp_gender.SelectedItem.Value + "','" + drp_country.SelectedItem.Value + "','" + txt_city.Text + "'," + txt_mobile.Text + ",'" + drp_sque.SelectedItem.Text + "','" + txt_ans.Text + "','')";
            cmd = new SqlCommand(qu);
            cmd.Connection = cn;
            cmd.ExecuteNonQuery();
            lblerr.Text = "User is Registered.";
            Response.Redirect("Login.aspx");
        }
    }
}

推荐答案

1.检查您的web.config中的连接字符串.
2.如果存在连接字符串,请检查它是否指向右DB.
3.检查安全性和身份验证参数是否正确传递.


我的建议是从Visual Studio浏览数据库.从属性窗口获取连接字符串.在web.config中使用此连接字符串.
1. Check your web.config for the connection string.
2. If connection string is present check it points to right DB.
3. Check if the security and authentication parameters are passes correctly.


My suggestion browse the database from visual studio. get the connection string from the properties window. use this connection string in web.config.


尝试替换

Try replacing

cn = new SqlConnection(ConfigurationManager.AppSettings["cn"]);




with

cn = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);


检查您是否能够连接到数据库,即您对数据库具有适当的权限,并且连接字符串正确.
Check that you are able to connect to the database i.e. you have the appropriate permissions to the database and that your connection string is correct.


这篇关于嘿,我收到打开错误,请为我解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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