如何创建C#Web应用程序以在远程Sql Server上运行查询 [英] How to create a C# Web Application to run a query on a remote Sql Server

查看:79
本文介绍了如何创建C#Web应用程序以在远程Sql Server上运行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个C#Web应用程序,从用户那里获取远程Sql服务器的服务器名称,实例,用户和密码,并在其数据库上运行查询。我还想保存远程Sql Servers信息以便重用它们。请帮我怎么开始。是否必须使用SMO?

推荐答案

基本上,您将从中形成 ConnectionString 用户输入并连接到数据库。

如果不使用 SMO ,您可以通过 ADO.NET实现任务对象。



您需要形成 ConnectionString ,然后使用<连接到该服务器code> SqlConnection Class。

初始化 SqlCommand Class and do执行查询。



您可以将该信息保存在数据库, web.config 或服务器中的其他文件中。
Basically, you will form the ConnectionString from the User Inputs and connect to the Database.
Without using SMO, you can achieve the task by ADO.NET Objects.

You need to form that ConnectionString, then Connect to that Server using SqlConnection Class.
Initialize SqlCommand Class and do Execute the query.

You can save that info either in Database, web.config or some other files in your Server.


这篇关于如何创建C#Web应用程序以在远程Sql Server上运行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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