如何删除此错误...从对象类型system.data.sqlclient.sqlconnection到已知的托管提供程序本机类型不存在映射。 [英] How do I remove this error ...no mapping exists from object type system.data.sqlclient.sqlconnection to a known managed provider native type.

查看:217
本文介绍了如何删除此错误...从对象类型system.data.sqlclient.sqlconnection到已知的托管提供程序本机类型不存在映射。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的是错误..

从对象类型System.Data.SqlClient.SqlConnection到已知的托管提供者本机类型不存在映射。



我尝试过:



这是我正在尝试的代码..

i have get is error ..
No mapping exists from object type System.Data.SqlClient.SqlConnection to a known managed provider native type.

What I have tried:

Here is my code which i am trying ..

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Dbconnection"].ToString());
                 con.Open();
                 string username = TextBox1.Text;
                 string password = TextBox2.Text;
                 SqlCommand cmd = new SqlCommand("dbo.spgetdata", con);
                 cmd.CommandType = CommandType.StoredProcedure;
                 
                 SqlParameter parm = new SqlParameter("@username", TextBox1.Text.Trim());
                 SqlParameter cpu = new SqlParameter("@password", TextBox2.Text.Trim());
                 SqlParameter da = new SqlParameter("@alreadyin", con);
                 cmd.Parameters.Add(parm);
                 cmd.Parameters.Add(cpu);
                 cmd.Parameters.Add(da);

                 SqlDataReader records = cmd.ExecuteReader();
                 records.Read();
                 if (records.HasRows)
                 {
                     if (records[2].ToString() == password)
                     {
                         Session["user"] = username;

                         Response.Redirect("~/welcome.aspx");
                     }
                 }

推荐答案

您不能将SqlConnection设置为存储过程的参数 - 或者任何其他查询 - 因为它对SQL Server没有任何用处,如果它被传递:SQL Server不知道如何处理它,因为它没有建立连接,它响应来自其他应用程序的连接请求。

我不知道你对SP的期望 - 我看不到 - 但我首先看一下程序,看看它对参数的期望是什么当它得到它。
You can't set an SqlConnection as a parameter to a stored procedure - or any other query - as it isn't of any use to SQL Server if it was passed through: SQL Server doesn't have any idea what to do with it as it doesn't establish connections, it responds to connection requests from other applications.
I have no idea what you expect in your SP - I can't see that - but I'd start by looking at the procedure and see what it expects to be able to do with the parameter when it gets it.


这篇关于如何删除此错误...从对象类型system.data.sqlclient.sqlconnection到已知的托管提供程序本机类型不存在映射。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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