无法打开登录请求的数据库“WebApi2BookDb”。登录失败。用户'Domain \ myusername'登录失败

时间:2021-03-13 13:18:22

I am trying to create Web API following this book http://www.apress.com/9781484201107?gtmf=c. I got to the end of chapter 5 and when I run my solution I got this error message:

我正在尝试按照本书http://www.apress.com/9781484201107?gtmf=c创建Web API。我到了第5章的末尾,当我运行我的解决方案时,我收到了以下错误消息:

Cannot open database "WebApi2BookDb" requested by the login. The login failed. Login failed for user 'Domain\myusername'.

无法打开登录请求的数据库“WebApi2BookDb”。登录失败。用户'Domain \ myusername'登录失败。

I thought that maybe I have messed up somwhere but when I downloaded source (available here Chapter 5: http://www.apress.com/downloadable/download/sample/sample_id/1577/) I got the same exact message.

我想也许我搞砸了somwhere但是当我下载源码时(可在这里获得第5章:http://www.apress.com/downloadable/download/sample/sample_id/1577/)我得到了同样的确切消息。

The connection string is: <add name="WebApi2BookDb" providerName="System.Data.SqlClient" connectionString="Server=.;initial catalog=WebApi2BookDb;Integrated Security=True;Application Name=WebApi2Book API Website" />

连接字符串是:

I am using Visual Studio 2013. What could be solution for this problem?

我正在使用Visual Studio 2013.这个问题可以解决什么问题?

Supposedly sending this request:

据称发送此请求:

POST ht tp://localhost:61589/api/v1/tasks HTTP/1.1 Content-Type: text/json {"Subject":"Fix something important"}

POST ht tp:// localhost:61589 / api / v1 / tasks HTTP / 1.1 Content-Type:text / json {“Subject”:“修复重要的东西”}

You should get response that should look something like this:

您应该得到应该看起来像这样的响应:

HTTP/1.1 201 Created Content-Type: text/json; charset=utf-8 Loation: ht tp://localhost:61589/api/v1/tasks/10 {"TaskId":10,"Subject":"Fix something important","StartDate":null,"DueDate":null, "CreatedDate":"2014-05-04T02:52:39.9872623Z","CompletedDate":null, "Status":{"StatusId":1,"Name":"Not Started","Ordinal":0},"Assignees":[], "Links":[{"Rel":"self","Href":"ht tp://localhost:61589/api/v1/tasks","Method":"GET"}]}

HTTP / 1.1 201创建的内容类型:text / json; charset = utf-8 Loation:ht tp:// localhost:61589 / api / v1 / tasks / 10 {“TaskId”:10,“Subject”:“修复重要的东西”,“StartDate”:null,“DueDate”: null,“CreatedDate”:“2014-05-04T02:52:39.9872623Z”,“CompletedDate”:null,“Status”:{“StatusId”:1,“Name”:“Not Started”,“Ordinal”:0 },“Assignees”:[],“Links”:[{“Rel”:“self”,“Href”:“ht tp:// localhost:61589 / api / v1 / tasks”,“Method”:“GET “}]}

2 个解决方案

#1


1  

I've just run into this problem myself. This is what you need to do:

我自己也遇到过这个问题。这是你需要做的:

  1. Open the solution in visual studio containing the code from chapter 5.
  2. 在visual studio中打开包含第5章代码的解决方案。

  3. Make sure you can build the "WebApi2BookDb" project. If you are having issues building this project see this stack overflow post.
  4. 确保您可以构建“WebApi2BookDb”项目。如果您在构建此项目时遇到问题,请参阅此堆栈溢出帖子。

  5. Create a database in SSMS called: "WebApi2BookDb".
  6. 在SSMS中创建一个名为“WebApi2BookDb”的数据库。

  7. Right click on the WebApi2BookDb project in visual studio and select publish.
  8. 右键单击visual studio中的WebApi2BookDb项目,然后选择发布。

  9. Click on Edit.
  10. 单击“编辑”。

  11. Enter "." for the server name or the name of your local SQL server instance.
  12. 输入“。”用于服务器名称或本地SQL Server实例的名称。

  13. Enter the username / password or use windows authentication.
  14. 输入用户名/密码或使用Windows身份验证。

  15. Select the "WebApi2BookDb" database.
  16. 选择“WebApi2BookDb”数据库。

  17. Test the connection.
  18. 测试连接。

  19. Click OK.
  20. Click Publish.

You should then be able to run the application without any issues.

然后,您应该能够毫无问题地运行应用程序。

You will then need to download fiddler. Once installed and running you will need to create a Post Request:

然后,您将需要下载fiddler。安装并运行后,您需要创建一个Post Request:

  1. Open Fiddler
  2. Click on the Composter tab.
  3. 单击Composter选项卡。

  4. Change the drop down list to "Post"
  5. 将下拉列表更改为“发布”

  6. Enter the URL e.g. http://localhost:61589/api/v1/tasks/ (Yours might be different).
  7. 输入网址,例如http:// localhost:61589 / api / v1 / tasks /(你的可能会有所不同)。

  8. Ensure Http/1.1 is selected from the drop down list.
  9. 确保从下拉列表中选择Http / 1.1。

  10. The content type should be as follows: Content-Type: text/json
  11. 内容类型应如下所示:Content-Type:text / json

  12. In the request body enter: {"Subject":"Fix something important"}
  13. 在请求正文中输入:{“主题”:“修复重要内容”}

  14. Click on the "Execute" button.
  15. 单击“执行”按钮。

You should then get a successful response and a new row should be added in your database!

然后,您应该获得成功的响应,并且应该在数据库中添加新行!

#2


0  

The error tells you exactly what is wrong. It can't open the WebApi2BookDb database, which, given your connection string, probably doesn't exist. You need to create that database.

错误告诉您到底出了什么问题。它无法打开WebApi2BookDb数据库,在给定连接字符串的情况下,该数据库可能不存在。您需要创建该数据库。

#1


1  

I've just run into this problem myself. This is what you need to do:

我自己也遇到过这个问题。这是你需要做的:

  1. Open the solution in visual studio containing the code from chapter 5.
  2. 在visual studio中打开包含第5章代码的解决方案。

  3. Make sure you can build the "WebApi2BookDb" project. If you are having issues building this project see this stack overflow post.
  4. 确保您可以构建“WebApi2BookDb”项目。如果您在构建此项目时遇到问题,请参阅此堆栈溢出帖子。

  5. Create a database in SSMS called: "WebApi2BookDb".
  6. 在SSMS中创建一个名为“WebApi2BookDb”的数据库。

  7. Right click on the WebApi2BookDb project in visual studio and select publish.
  8. 右键单击visual studio中的WebApi2BookDb项目,然后选择发布。

  9. Click on Edit.
  10. 单击“编辑”。

  11. Enter "." for the server name or the name of your local SQL server instance.
  12. 输入“。”用于服务器名称或本地SQL Server实例的名称。

  13. Enter the username / password or use windows authentication.
  14. 输入用户名/密码或使用Windows身份验证。

  15. Select the "WebApi2BookDb" database.
  16. 选择“WebApi2BookDb”数据库。

  17. Test the connection.
  18. 测试连接。

  19. Click OK.
  20. Click Publish.

You should then be able to run the application without any issues.

然后,您应该能够毫无问题地运行应用程序。

You will then need to download fiddler. Once installed and running you will need to create a Post Request:

然后,您将需要下载fiddler。安装并运行后,您需要创建一个Post Request:

  1. Open Fiddler
  2. Click on the Composter tab.
  3. 单击Composter选项卡。

  4. Change the drop down list to "Post"
  5. 将下拉列表更改为“发布”

  6. Enter the URL e.g. http://localhost:61589/api/v1/tasks/ (Yours might be different).
  7. 输入网址,例如http:// localhost:61589 / api / v1 / tasks /(你的可能会有所不同)。

  8. Ensure Http/1.1 is selected from the drop down list.
  9. 确保从下拉列表中选择Http / 1.1。

  10. The content type should be as follows: Content-Type: text/json
  11. 内容类型应如下所示:Content-Type:text / json

  12. In the request body enter: {"Subject":"Fix something important"}
  13. 在请求正文中输入:{“主题”:“修复重要内容”}

  14. Click on the "Execute" button.
  15. 单击“执行”按钮。

You should then get a successful response and a new row should be added in your database!

然后,您应该获得成功的响应,并且应该在数据库中添加新行!

#2


0  

The error tells you exactly what is wrong. It can't open the WebApi2BookDb database, which, given your connection string, probably doesn't exist. You need to create that database.

错误告诉您到底出了什么问题。它无法打开WebApi2BookDb数据库,在给定连接字符串的情况下,该数据库可能不存在。您需要创建该数据库。