如何使用.net应用程序设置运行sql脚本? [英] How to sql script run with .net application setup?

查看:67
本文介绍了如何使用.net应用程序设置运行sql脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在运行sql脚本时遇到了问题。

我的脚本没有运行.Net Windows应用程序安装程序。

我已经为SQL Script创建了Installer类,但我的数据库没有附加。



所以,请帮助我。

怎么可能呢?



感谢你。

Ankit Agarwal

软件工程师

Hello,

I jave a problem with sql script run.
My script is not running with .Net Windows Application Setup.
I have created Installer class for SQL Script, but my database not attaching.

So, please help me.
How could that possible?

Thank U.
Ankit Agarwal
Software Engineer

推荐答案

部署应用程序和数据库 [ ^ ]


您好b $ b

您可以使用bellow类进行管理。



Hi
You can use from bellow class for manage that.

-----------------------------------------------------------------------------------
    public class DBManagement
    {
        public SqlConnection OpenConnection()
        {
            string connectionString = "Data Source = [YourServerName]; Initial Catalog = [YourDatabaseName]; User ID = [YourSqlUserName]; Password = [YourSqlUserPassword]";

            SqlConnection connection = null;

            try
            {
                connection = new SqlConnection(connectionString);
                connection.Open();
            }
            catch
            {
                Console.WriteLine("DataBase is not reachable....");
            }

            return connection;

        }

        public DataTable Execute(string queryString)
        {
            SqlConnection connection = OpenConnection();

            SqlCommand query = new SqlCommand(queryString, connection);

            DataTable resultTable = new DataTable();

            SqlDataAdapter adopter = new SqlDataAdapter(query);

            adopter.Fill(resultTable);

            connection.Close();

            return resultTable;
        }
    }
-----------------------------------------------------------------------------------





您可以将[youparameter]直接发送到此课程的方法。



我希望它有用。



You can send [youparameter] directly to your methods of this class.

I hope it''s helpful.


这篇关于如何使用.net应用程序设置运行sql脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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