[英]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.