如何使用SqlPlus数据库使用C#设置登录页面? [英] how to set up login page with C# using SqlPlus database?

查看:104
本文介绍了如何使用SqlPlus数据库使用C#设置登录页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

如果有人可以帮我解决这个问题我真的很感激。

我使用VS2012 C#和SqlPlus作为数据库。要设置一个登录页面我跟我们对sqlserver的操作方式一样,我不确定这是不是我们这样做的方式。下面的代码是我正在使用的,但它不起作用,并且不对应于logi页面后面的代码。我得到的第一个错误是不支持的关键字:'unicode'所以我从配置中删除了unicode然后什么都没有用,我删除了unicode后出现了另一个问题系统找不到指定的文件conn.Open();

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Configuration;
使用 System.Security;
使用 System.Text;
使用 System.Collections;
使用 System.Data;
使用 System.Data.OracleClient;


public partial class Account_Login1:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{

}
protected void Button_login_Click( object sender,EventArgs e)
{
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings [ ConnectionString的]的ConnectionString)。
conn.Open();
string checkuser = SELECT COUNT(* )FROM USERERS USER USER =' + textusername.Text + ';
OracleCommand com = new OracleCommand(checkuser,conn);
int temp = Convert.ToInt32(com.ExecuteScalar()。ToString());
conn.Close();
if (temp == 1
{
conn。打开();
string checkpasswordQuery = 从用户中选择密码在哪里USER_NAME =' + textusername.Text + ';
OracleCommand passcom = new OracleCommand(checkpasswordQuery,conn);
string password = passcom.ExecuteScalar()。ToString()。替换( );
if (password == Textpassword.Text)
{
Session [ NEW] = textusername.Text;
Response.Write( 密码正确);
}
else
{
Response.Write( 密码不正确);
Response.Redirect( Default2.aspx);
}
}
else
{
Response.Write( 用户名不正确);
}





我的配置代码




 < ?xml version =   1.0>  
< configuration>
< connectionStrings>

< add name = ConnectionString connectionString = 数据源= **;持久安全信息= True;用户ID = **;密码= **;
providerName = System.Data.OracleClient />
< / connectionStrings >
< system.web>
< compilation debug = true targetFramework = 4.5 >
< assemblies>
< add assembly = 系统。 Data.OracleClient,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = B77A5C561934E089 />
< / 议程 >
< / 编译 >
< httpRuntime targetFramework = 4.5 />
< / system.web >
< / 配置 >

解决方案

开始:



0 )我假设您的意思是Oracle数据库 - SqlPlus只是Oracle的命令行界面。

1)不要使用System.Data.OracleClient(好吧,继续只是让它工作,但它已被弃用或几乎如此)。

2)下载Oracle的数据访问工具。

3)SqlConnection和SqlCommand仅适用于SQL Server;你需要使用Oracle的那些。



编辑:



4)不要存储纯文本密码。

5)不要使用连接;使用参数化查询。

6)不要在C#代码中执行比较。

7)当用户无法登录时,请勿指出原因问题 - 不要说用户名不存在。



此外:



)将数据访问代码与UI代码分开。







 System.Data.OracleClient命名空间

System.Data.OracleClient命名空间是Oracle的.NET Framework数据提供程序。

不推荐使用System.Data.OracleClient中的此类型,并将在.NET Framework的未来版本中删除。有关更多信息,请参阅Oracle和ADO.NET。





http://msdn.microsoft.com/en-us/library/system.data.oracleclient(v = vs.110)。 aspx [ ^ ]







 System.Data.OracleClient命名空间

注意:此命名空间,类或成员仅在.NET Framework 1.1版中受支持。
System.Data.OracleClient命名空间是Oracle的.NET Framework数据提供程序。





http://msdn.microsoft.com/en-us/library/system.data .oracleclient(v = vs.71).aspx [ ^ ]


我将类从sql更改为oracle,我还删除了一些不支持的元素预言

Hi guys
I will really appreciated if someone can help me sort out this issue.
I'm using VS2012 C# and SqlPlus as database. To set up a Login page I followed same way as what we do for sqlserver which I'm not sure if this is the way we do it. the code bellow is what I'm using at the moment but its not working and not corresponding to the code behind the logi-page.The first error I got is the Keyword not supported: 'unicode' so I removed the unicode from my config then nothing is working, another issue comes after I removed the unicode is The system cannot find the file specified conn.Open(); .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Security;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.OracleClient;


public partial class Account_Login1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button_login_Click(object sender, EventArgs e)
    {
        OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        conn.Open();
        string checkuser = " SELECT COUNT (*) FROM USERS WHERE USER_NAME='" + textusername.Text + "'";
        OracleCommand com = new OracleCommand(checkuser, conn);
        int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
        conn.Close();
        if (temp == 1)
        {
            conn.Open();
            string checkpasswordQuery = " SELECT PASSWORD FROM USERS WHERE USER_NAME='" + textusername.Text + "'";
            OracleCommand passcom = new OracleCommand(checkpasswordQuery, conn);
            string password = passcom.ExecuteScalar().ToString().Replace("", "");
            if (password == Textpassword.Text)
            {
                Session["NEW"] = textusername.Text;
                Response.Write("password is correct");
            }
            else
            {
                Response.Write("password is not correct");
                Response.Redirect("Default2.aspx");
            }
        }
        else
        {
            Response.Write("username is not correct");
        }



my configuration code


<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    
    <add name="ConnectionString" connectionString="Data Source=**;Persist Security Info=True;User ID=**;Password=**;"
      providerName="System.Data.OracleClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
</configuration>

解决方案

To start:

0) I assume you mean an Oracle database -- SqlPlus is just a command line interface to Oracle.
1) Don't use System.Data.OracleClient (well, go ahead just to get it working, but it's deprecated or nearly so).
2) Download Oracle's data access tools.
3) SqlConnection and SqlCommand are only for SQL Server; you'll need to use the ones for Oracle.

Edit:

4) Don't store plain text passwords.
5) Don't use concatenation; use parameterized queries.
6) Don't perform the comparison in your C# code.
7) When a user can't log in, DO NOT indicate the cause of the problem -- don't say that the user name doesn't exist.

Furthermore:

8) Separate the Data Acess code from the UI code.



System.Data.OracleClient Namespace

The System.Data.OracleClient namespace is the .NET Framework Data Provider for Oracle.

This types in System.Data.OracleClient are deprecated and will be removed in a future version of the .NET Framework. For more information, see Oracle and ADO.NET.



http://msdn.microsoft.com/en-us/library/system.data.oracleclient(v=vs.110).aspx[^]



System.Data.OracleClient Namespace

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework. 
The System.Data.OracleClient namespace is the .NET Framework Data Provider for Oracle.



http://msdn.microsoft.com/en-us/library/system.data.oracleclient(v=vs.71).aspx[^]


I changed the classes from sql to oracle and I also removed some elements that is not supported in oracle


这篇关于如何使用SqlPlus数据库使用C#设置登录页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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