如何创建C#Web应用程序以在远程Sql Server上运行查询 [英] How to create a C# Web Application to run a query on a remote Sql Server
本文介绍了如何创建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 theConnectionString
from the User Inputs and connect to the Database.
Without usingSMO
, you can achieve the task byADO.NET
Objects.
You need to form thatConnectionString
, then Connect to that Server usingSqlConnection
Class.
InitializeSqlCommand
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屋!
查看全文