简体   繁体   English

我可以在没有Web服务的情况下从C#桌面应用程序连接到Sharepoint上的SQL Server数据库吗?

[英]Can I connect from my C# desk top application to an SQL Server database on Sharepoint without a web service?

I have created a desktop application in C# with an SQL Server database that holds my departments quotations. 我已经使用SQL Server数据库在C#中创建了一个桌面应用程序,该数据库包含我的部门报价。 We now have a Sharepoint site and I will have to store this data there so that my coworkers abroad can use this app and add, query data themselves. 我们现在有一个Sharepoint网站,我将不得不在此存储数据,以便我在国外的同事可以使用此应用程序并自己添加,查询数据。 I am familiar with reading data from web services using JSON, but not sure if creating a web service is necessary for an application to connect to a database stored on a server. 我熟悉使用JSON从Web服务读取数据,但是不确定是否需要创建Web服务才能使应用程序连接到存储在服务器上的数据库。 Do I simply build an HTTP request with credentials to the Sharepoint site, then add the directory folder to the header and query the database? 我是否只是简单地将一个带有凭据的HTTP请求构建到Sharepoint站点,然后将目录文件夹添加到标头并查询数据库?

First, you or your dba need to backup/restore your desktop app's database to the same instance SharePoint is connected to. 首先,您或您的dba需要将桌面应用程序的数据库备份/还原到SharePoint连接到的同一实例。 If you don't want to migrate existing data, create a new database using the same schema. 如果您不想迁移现有数据,请使用相同的架构创建一个新数据库。

Next you'll want to create a sql user account that you can use in your connection string. 接下来,您将要创建一个可以在连接字符串中使用的sql用户帐户。 Update your desktop app's connection string to use the new sql instance, username, and password. 更新您的桌面应用程序的连接字符串,以使用新的sql实例,用户名和密码。

No, you don't need to create a service to access a database on a server. 不,您不需要创建服务即可访问服务器上的数据库。 What you are actually asking is how to read from (write to) database on C#. 您实际上要问的是如何在C#上读取(写入)数据库。 As I understand you already have an access to the database (user account with granted access and password). 据我了解,您已经可以访问数据库(具有授予访问权限和密码的用户帐户)。 You will need to use ADO.NET - it's a technology for data access. 您将需要使用ADO.NET-这是一种用于数据访问的技术。

You will utilize SqlConnection, SqlDataReader and SqlCommand classes. 您将利用SqlConnection,SqlDataReader和SqlCommand类。 check for example this example: Reading values from SQL database in C# 例如,检查以下示例: 在C#中从SQL数据库读取值

There is a newer technology from Microsoft called Entity Framework. Microsoft提供了一种名为Entity Framework的较新技术。 It provides better solution for working with databases. 它为使用数据库提供了更好的解决方案。 Use it if you need to work with many tables and complicated queries. 如果您需要处理许多表和复杂查询,请使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从C#Web应用程序返回401的Jira Service Desk API调用 - Jira Service Desk API call returning 401 from c# web application 无法从Windows应用程序C#连接到SQL Server数据库 - unable to connect to sql server database from windows application c# 在连接到数据库之前,如何检查MySQL服务器是否从C#MOBILE处于活动状态 - How can i check if MySQL server is alive from C# MOBILE before i connect to my database 我可以使用C#锁来防止Web应用程序中的SQL Server死锁吗? - Can I use C# locks to prevent SQL Server deadlocks in my web application? 我想将图像从C#表单应用程序保存到SQL Server数据库 - I want to save an image from my C# form application to SQL Server Database 如何确保C#应用程序只能从SQL Server数据库读取? - How can I ensure that my C# application can only read from the SQL Server databases? 如何检查我是否有来自 SQL 服务器数据库的图像或不使用 C# - How can I check if I have an image from my SQL Server database or not using C# MS SQL —可以让多个用户从Web服务(c#)连接/读取/写入数据库吗? - MS SQL — Okay for multiple users to connect/read/write to database from a web service (c#)? 将C#Windows应用程序连接到基于Web的Sql Server - Connect C# windows application to web based Sql server 将 C# MVC 应用程序连接到远程 SQL Server 数据库 - Connect a C# MVC application to a remote SQL Server database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM