我想将数据库连接为远程连接。 [英] I would like to connect the database as remote connection.

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

问题描述

这里我开发了一个应用程序,根据存储在sql server中的数据,应该正确输入用户名和密码。我有一个问题,我想集成这个远程运行。

这是我与数据库连接的代码,但我想访问远程位置而不需要数据库。







here i have developed a application where username and password should be entered correctly as per the data stored in sql server. i have a issue here i want to integrate this to run remotely.
Here is the code i have connected with database but i want to access it remote location without database.



private void button1_Click_1(object sender, EventArgs e)
       {

            string cs = @"Data Source=.;Database=master;Integrated Security=True;";
        //btn_Submit Click event

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Please provide UserName and Password");
                return;
            }
            try
            {
                //Create SqlConnection
                SqlConnection con = new SqlConnection(cs);
                SqlCommand cmd = new SqlCommand("Select * from Register where Usernmae=@username and Password=@password", con);
                cmd.Parameters.AddWithValue("@username", textBox1.Text);
                cmd.Parameters.AddWithValue("@password", textBox2.Text);
                con.Open();
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;
                //If count is equal to 1, than show frmMain form
                if (count > 0)
                {

                    this.Hide();
                    Dashboard dsb = new Dashboard();
                    dsb.Show();
                }
                else
                {
                    MessageBox.Show("Login Failed!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }





我的尝试:



这里我试过在sql server中存储数据,我想使用查询调用数据,但现在我想从不同的位置访问该数据远程位置。



What I have tried:

here i have tried by storing data in sql server and i suppose to call the data using the query but now i want to access that data remote location from different location.

推荐答案

所以将你的连接字符串存储在某种形式的配置文件中 - 我不知道你的环境是什么,所以我不能建议怎么做 - 并从中读取它。

永远不要硬编码连接字符串:它们在开发和生产中总是会有所不同(或者你会后来真的后悔 - 当你在dev中犯了错误并破坏了数据库......)
So store your connection string in a configuration file of some form - I have no idea what your environment is, so I can't suggest how to do that - and read it from that.
Never hard code connection strings: they will always be different in development and production (or you will really regret it later - when you make a mistake in dev and destroy the DB...)

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

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