使用visual studio的Sql和C# [英] Sql and C# using visual studio

查看:76
本文介绍了使用visual studio的Sql和C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有SQL适配器或执行程序,如何让sql winform应用程序可以被局域网中的其他用户访问



我尝试了什么:



i我正在使用visual studio C#和SQL

解决方案

这将是一个非常高级的答案。



您不需要将SQL视为作为应用程序一部分部署的依赖项,这可能是一个糟糕的设计但我不喜欢我不知道你要做什么。



您应该去的路线是在专用的盒子上安装sql server本身,然后让你的应用程序访问sql server通过ado.net或实体框架(或数百万个数据库连接选项中的任何其他选项)连接到它。还有其他选择,例如创建一个安静的API并将API公开给你的应用程序,让winforms应用程序只使用API​​,而不必担心有大量不同的客户端机器连接到sql server本身。无论如何,这都将消除您必须在将运行winforms应用程序的每台客户端计算机上安装数据库连接依赖项。



我建议一个好的谷歌搜索作为第一个开始。



从winforms连接到sql server - Google搜索 [ ^ ]



第一个结果看起来很有希望



.net - 连接到SQL Server数据库C#-WinForms - 堆栈溢出 [ ^ ]



如果您开始使用并卡住,请随时回来明确解释您的问题,相关代码示例以及您尝试解决问题的说明,我相信您会找到有意义的帮助。


问题的问题,<我>你信任局域网上的每个人?或者,他们是否只是被允许阅读信息而不做其他事情?一种简单的方法是,为用户提供类似报告的界面,并要求他们输入自己的凭据 - 在数据库内创建的用户帐户 - 并管理他们有权访问的区域。有几个数据库引擎提供了这个,但到目前为止,这是仅使用数据库引擎执行此操作的最简单方法。



另一种方法是编写一个Web界面,比如基于ASP.NET的Web API ,因为你正在谈论WinForms ),他们可以在这里使用数据库的后端服务。网络界面提供的主要功能是,



  1. 通过任何网络浏览器快速轻松访问。
  2. 管理谁可以访问资源,缓存,cookie和JWT可以轻松应用。
  3. 没有人可以直接访问数据库 - 最重要的一个!



在数据库中,主要问题是,特别是那些可在网络上访问的数据库,任何人都可以直接访问这些表。这是提供依赖于数据库的服务的最差方式。试想一下,一个人可以在数据库上执行什么。我会告诉你的。



虽然你可以说,可以生成一个临时表,或者可以生成一个只读表。但相信我,网络界面是一种简单的做事方式。如果我必须开发这种系统,我会把我的时间和精力投入到一个良好的Web前端,它抽象出对数据库的直接访问,并使用只读用户帐户(可以通过非管理员用户的连接字符串,以及仅为管理员提供的管理员或写入访问帐户。如果你写错了查询,这可以很容易地保护你免受SQL注入,因为用户根本就没有写访问权限。



虽然这看起来很重要,但我简单地说,创建具有读取或读写访问权限的单独帐户,然后使用这些帐户每个用户都可以从后端访问资源。



ASP.NET Web API | ASP.NET站点 [ ^ ]


how to make sql winform application to be accessible by other user in LAN when they don't have SQL adapter or executor

What I have tried:

i am using visual studio C# and SQL

解决方案

This is going to be a pretty high level answer.

You need to not think of SQL as a dependency that gets deployed as part of your application, that is likely a poor design but i don't know a thing about what you are attempting to do.

The route you should go is install sql server itself on a dedicated box, then give your application access to that sql server by connecting to it with ado.net or entity framework (or any other of the millions of DB connectivity options). There are other options to this to, like creating a restful API and exposing the API to your app and having your winforms app simply consume the API and not having to worry about a ton of different client machines having connectivity to the sql server itself.

Either way you go, this will eliminate you having to install DB connectivity dependencies on each of the client machines that will be running your winforms app.

I'd recommend a good google search as the first place to start.

connect to sql server from winforms - Google Search[^]

First result looks promising

.net - Connecting to SQL Server Database C#-WinForms - Stack Overflow[^]

If you get started on this and get stuck, feel free to come back with a clear explanation of your issue, relevant code samples and a description of what you've tried to resolve your issue and I am sure you will find meaningful help.


A question for question, do you trust everybody on the LAN? Or, are they just allowed to read the information and not do other stuff? One simple way to do is, provide a report-like interface to the users and ask them to enter their own credentials—the user accounts that are created inside the database—and manage what areas do they have access to. Several database engines provide this, and yet this is so far the simplest way to do this with only the database engine.

Yet another way to do this would be to write a web interface, like ASP.NET based Web API (since you are talking about WinForms), where they can consume the backend services for the database. The main features that a web interface would provide would be,


  1. Quick and easy access via any web browser.
  2. Manage who can access the resources, and caching, cookies, and JWT can be applied easily.
  3. Nobody has direct access to the database—most important one!


In the database, the major issue is, and especially those databases that are accessible on the network, that anybody can access the tables directly. Which is the worst way of providing the services that are depending on the database. Just imagine, what a person can execute on the database. I will leave you with that.

Although you can argue, that a temporary table can be generated, or a read-only table can be generated. But trust me, a web interface is an easy way of doing things. If I had to develop this kind of a system, I would be investing my time and effort in a good web front-end, that abstracts away the direct access to a database, and uses a read-only user account (can be controlled via a connection string) for non-admin users, and an admin or write-access provided account for the admins only. This can easily protect you from SQL Injection, in case you do write a bad query, since users won't have a write access at all.

Although this seems like a big thing, what I said, in a nutshell is, create separate accounts with read, or read-write access, then use those accounts for each individual user to access the resources from backend.

ASP.NET Web API | The ASP.NET Site[^]


这篇关于使用visual studio的Sql和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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