简体   繁体   English

ASP.NET:连接到SQL Server数据库

[英]ASP.NET: connecting to a sql server database

(very newbie question, please help if you can) (关于新手的问题,请帮助)

how do i connect visual web developer to sql server express 2008? 如何将Visual Web Developer连接到SQL Server Express 2008? in the Database Explorer, i right click on Data Connections, click Add Connection..., and in the Data source box i choose Microsoft SQL Server (sqlClient), which i'm guessing doesn't connect me to a database file, but to sql server express itself(?). 在数据库资源管理器中,我右键单击“数据连接”,再单击“添加连接...”,然后在“数据源”框中选择“ Microsoft SQL Server(sqlClient)”,我猜这并没有将我连接到数据库文件,但是到SQL Server表达自己(?)。 in the server name box when i click the drop down box, there's nothing there and that's where i get stuck. 在服务器名称框中,当我单击下拉框时,那里什么都没有,这就是我被卡住的地方。

can someone provide a link to how i can connect to sql server express; 有人可以提供我如何连接到sql server express的链接吗? preferably not an msdn link since i've been there and struggled with their walkthrough. 最好不要是msdn链接,因为我去过那里并且对他们的演练感到困惑。 thanks 谢谢

usually you can type in .\\SQLEXPRESS to connect to local SQL Server Express install... 通常,您可以键入.\\SQLEXPRESS以连接到本地SQL Server Express安装...

the dot means the computer you are on, like localhost, and the \\SQLEXPRESS is the SQL Server instance that the server is running on...this is the default instance name anyway for SQL Server Express... 点表示您正在使用的计算机,例如localhost,并且\\ SQLEXPRESS是服务器正在运行的SQL Server实例...这还是SQL Server Express的默认实例名称...

Sql Server Express is a server class database engine. Sql Server Express是服务器类数据库引擎。 That means that, yes, you do connect to the server rather than read/write directly to a file. 这意味着,是的,您确实连接到服务器,而不是直接读取/写入文件。 The server engine will then handle access to your data. 然后,服务器引擎将处理对您数据的访问。

This is important. 这个很重要。 It's the mechanism that allows sql server to safely handle situations like asp.net web sites, where each page request runs in a different thread and you might have many that all want to write to your database at about the same time. 它是允许sql Server安全处理asp.net网站等情况的机制,其中每个页面请求都在不同的线程中运行,并且您可能有许多人都希望几乎同时写入数据库。 If each process were just writing to the file, you'd have problems with data corruption. 如果每个进程都只是写入文件,则数据损坏会出现问题。 Sending requests to a single server process allows it to properly ensure each item runs in a separate, isolated transaction and handle those operations safely. 将请求发送到单个服务器进程可以使其正确地确保每个项目在单独的隔离事务中运行,并安全地处理这些操作。

This mechanism is also important for performance. 该机制对于性能也很重要。 It allows the system to do things like pre-load tables and indexes into memory once, for use by any process that happens to make a request on that data. 它允许系统一次执行将表和索引预加载到内存等操作,以供碰巧对该数据发出请求的任何进程使用。 This is why a server engine like sql server express or even mysql will always be able to beat an in-process engine like sqlite in terms of performance as your data scales, even though sqlite is more less resource intensive initially and often seems faster on small data or small loads. 这就是为什么在数据扩展方面,像sql server express甚至mysql这样的服务器引擎始终可以在性能上击败像sqlite这样的进程内引擎,即使sqlite最初的资源占用较少,并且在小型服务器上通常看起来更快数据或少量负载。

The need to have this server process running is also why you should not use sql server express for local desktop applications. 也需要运行此服务器进程的原因也是为什么您应对本地桌面应用程序使用sql server express的原因。 In that situation, you don't want to force your users to have a server processes sitting there 24/7 using memory to cache index and table data you may only reference occasionally. 在这种情况下,您不想强迫用户让服务器进程全天候24/7地坐在那里,使用内存来缓存您可能偶尔引用的索引和表数据。 This is where your sql server compacts, sqlites, and access databases come in. 这是您的sql server压缩,sqlite和access数据库进入的地方。

As for your specific connection problem, there are a lot of things that could cause this. 至于您的特定连接问题,可能是由很多原因引起的。 Are you sure sql server express is currently installed and running on your system? 您确定系统上当前已安装并正在运行sql server express吗? What happens if you just type "localhost" or "./SQLEXPRESS" in the box manually? 如果仅在框中手动键入“ localhost”或“ ./SQLEXPRESS”会发生什么?

click on the Tools in Visual studio. 单击Visual Studio中的工具。 choose Connect to Database. 选择连接到数据库。 choose Data Source.. Microsoft Sql Server from the "choose Data Source" window. 从“选择数据源”窗口中选择“数据源”。Microsoft Sql Server。 and then continue. 然后继续。 new window will be open "Add Connection" type Microsoft SQL Server (SqlClient) in "Data source" and choose Server Name. 新窗口将打开。在“数据源”中键入“ Microsoft SQL Server(SqlClient)”,然后选择“服务器名称”。 Select your database name from the Select or enter a database name. 从“选择”中选择数据库名称或输入数据库名称。 and click on Test Connection. 然后单击测试连接。

in test connection window copy the connection string ... and you can use it in ur application'web.config. 在测试连接窗口中,复制连接字符串...,然后可以在您的application'web.config中使用它。 or on ur page 或您的页面上

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM