Web.config连接字符串 - 连接SQL服务器 [英] Web.config connection string - connect SQL server

查看:87
本文介绍了Web.config连接字符串 - 连接SQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我是环境的初学者MVC .NET

我正在尝试将我的SQL数据库连接到我的项目MVC,但老实说我不知道理解要作为参数放什么。

我的连接db sql是:

服务器名称:CBL-LT138388 \ SVQPRESS

实例名称:SQLEXPRESS

数据库:WebShop

用户名:sa

密码:mypassword







Hello guys!
I quite a beginner for the environment MVC .NET
I am trying to connect my SQL db to my project MVC, but honestly I do not understand what to put as parameter.
My connection db sql is:
Server Name: CBL-LT138388\SQLEXPRESS
Instance Name: SQLEXPRESS
database : WebShop
User Name: sa
password: mypassword



<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost; database=WebShop; Integrated Security=True; uid=sa;password=" />
</connectionStrings>





我做了什么:

1.创建了一个新项目MVC。

2.试图修改我的myConnectionString,这允许我注册一个新用户并与他们联系。

3.试图修改我的connectionStrings



当我尝试执行程序并注册一个新用户时,我没有看到任何创建的表。



我有什么试过:





What I have done:
1. Created a new project MVC.
2. trying to modify my myConnectionString, which allow me to register a new user and connect with them.
3. tried to modify my connectionStrings

When I try to executed the program, and register a new user, I do not see any table created.

What I have tried:

<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost; database=WebShop; Integrated Security=True; uid=sa;password=" />
</connectionStrings>

推荐答案

你的连接字符串看起来非常错误:你说你想要集成安全性,但是你提供了 - 非常危险 - 用户名sa和 - 可能无效 - 密码为空白。



获取有效的连接字符串非常简单:尝试在VS中设置连接服务器资源管理器窗格:

1)打开服务器资源管理器。

2)右键单击数据连接并选择添加连接

3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接按钮。

4)当连接正常时,按确定

5)在服务器资源管理器窗格中突出显示数据库,然后查看属性窗格。将显示连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中。



但是这不会为您创建任何表格。您需要创建它们并在开始其余部分之前设置一些测试数据。
Your connection string looks very wrong: you are saying that you want Integrated Security, but then you supply a - very dangerous - user name "sa" and a - probably invalid - password of blank.

Getting a valid connection string is pretty simple: try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

But that won't create any tables for you. You need to create them and possible set up some test data before you get started on the rest.


Oook我现在看到。

当我按照指示进行操作时你给我写了它自动创建一个connectionStrings:





Oook I see now.
When I follow the instruction which you wrote me it creates automatically a connectionStrings:


<connectionStrings>
  <add name="WebShopEntities" connectionString="metadata=res://*/DAL.ClientModel.csdl|res://*/DAL.ClientModel.ssdl|res://*/DAL.ClientModel.msl;provider=System.Data.SqlClient;provider connection string="data source=CBL-LT138388\SQLEXPRESS;initial catalog=WebShop;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

</connectionStrings>





非常感谢你们!



Thank you very much guys!!


这篇关于Web.config连接字符串 - 连接SQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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