本文介绍了运行连接到SQL DB的网页时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是编程世界的新手.尝试使用WPF将C#与sql db连接时遇到困难.

我想做什么?

运行一个网页,该网页会将网页中的信息插入db(客户信息)表中.
我使用了文本块来获取信息并添加到DataRow中.然后将DataRow插入到Dataset中,最后通过SqlDataAdapter更新数据库表.

源代码:

Hi guys,

I''m new to programming world. I am facing difficulty when trying to connect C# with sql db using WPF.

What I was trying to do?

Run a webpage which will insert the information in the webpage to the table in db(customer info).
I used the textblock to get the info(s) and add to the DataRow. Then insert the DataRow to the Dataset and finally update db table through SqlDataAdapter.

Source Code:

public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();
        }
        private void buttonUpdate_Click(object sender, RoutedEventArgs e)
        {
                SqlConnection conn = new SqlConnection();

                string connString = "server=gladiator\\sqlexpress; database=MoviesStorage; Integrated Security=SSPI; ";
                conn.ConnectionString = connString;
                conn.Open();

                string commString = "SELECT * FROM Customer_Info";
                SqlCommand comm = new SqlCommand(commString, conn);
                SqlDataAdapter dtAdapter = new SqlDataAdapter(comm);
                SqlCommandBuilder commBuilder = new SqlCommandBuilder(dtAdapter);

                DataSet dtSet = new DataSet();
                dtAdapter.Fill(dtSet, "Customer_Info");

                DataRow dtRow = dtSet.Tables["Customer_Info"].NewRow();
                dtRow["myID"] = textID.Text;
                dtRow["myName"] = textName.Text;
                dtRow["myIC"] = textIC.Text;
                dtRow["myContact"] = textContact.Text;
                dtSet.Tables["Customer_Info"].Rows.Add(dtRow);

                dtAdapter.Update(dtSet, "Customer_Info");
                conn.Close();
        }
}


编译器退出时没有错误.但是一旦执行,就会抛出一条我不理解的异常消息.它发生在conn.Open()行中.

引发异常:
未知模块中发生了类型为"System.Security.SecurityException"的未处理的异常."


有人能帮助我吗?与该问题有关的任何其他链接也将受到赞赏.

谢谢,
Skunhhead


The compiler exits without erros. But once I execute, there is an exception message thrown which I do not understand. It happens in line conn.Open().

Exception thrown:
"An unhandled exception of type ''System.Security.SecurityException'' occurred in Unknown Module."


Does anyone able to help me on this? Any other link relating to this problem are also appreciated.

Thanks,
Skunhhead

推荐答案

string connString = "server=gladiator\\sqlexpress; database=MoviesStorage; Integrated Security=True;"; //Or
//string connString = "server=gladiator\\sqlexpress; database=MoviesStorage;uid=" + username + ";pwd=" + password + ";";  



请查看此链接,也许对您有帮助:
http://www.secnewsgroups.net/dotnet/t1385-security-exception-related- network.aspx [ ^ ]



Please view this link, maybe it helps you:
http://www.secnewsgroups.net/dotnet/t1385-security-exception-related-network.aspx[^]




这篇关于运行连接到SQL DB的网页时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:47