从objectcontext.Connection.ConnectionString获取connectionstring的问题

时间:2021-04-20 01:46:16

I really appreciate it if you could ask my question. After I call myObjectContext.myEntitySet.ToList() method in my entity framework context, the password part from connectionstring in myObjectContext.Connection.ConnectionString is gone.is it a bug? thanks very much for your help.

如果你能提出我的问题,我真的很感激。在我的实体框架上下文中调用myObjectContext.myEntitySet.ToList()方法后,myObjectContext.Connection.ConnectionString中来自connectionstring的密码部分消失了。这是一个错误吗?非常感谢您的帮助。

1 个解决方案

#1


2  

This is by design. The password is removed to protect you. If you really want to keep the password there you can add the following to your connection string: Persist Security Info=True;

这是设计的。密码已删除以保护您。如果您确实要保留密码,可以在连接字符串中添加以下内容:Persist Security Info = True;

So then your connection string should look something like this:

那么你的连接字符串应该是这样的:

Data Source=server;Initial Catalog=database;User ID=user;Password=password;Persist Security Info=True;

Be aware that this is a security risk. If your database server supports windows authentication you should use that instead. Then your connection string would be as follows:

请注意,这是一种安全风险。如果您的数据库服务器支持Windows身份验证,则应使用它。然后你的连接字符串如下:

Data Source=server;Initial Catalog=database;Integrated Security=True

As you can see this connection string doesn't contain a user name or password. Instead your windows user name and password is used. If you can you should use this instead of the former.

如您所见,此连接字符串不包含用户名或密码。而是使用您的Windows用户名和密码。如果可以,你应该使用它而不是前者。

#1


2  

This is by design. The password is removed to protect you. If you really want to keep the password there you can add the following to your connection string: Persist Security Info=True;

这是设计的。密码已删除以保护您。如果您确实要保留密码,可以在连接字符串中添加以下内容:Persist Security Info = True;

So then your connection string should look something like this:

那么你的连接字符串应该是这样的:

Data Source=server;Initial Catalog=database;User ID=user;Password=password;Persist Security Info=True;

Be aware that this is a security risk. If your database server supports windows authentication you should use that instead. Then your connection string would be as follows:

请注意,这是一种安全风险。如果您的数据库服务器支持Windows身份验证,则应使用它。然后你的连接字符串如下:

Data Source=server;Initial Catalog=database;Integrated Security=True

As you can see this connection string doesn't contain a user name or password. Instead your windows user name and password is used. If you can you should use this instead of the former.

如您所见,此连接字符串不包含用户名或密码。而是使用您的Windows用户名和密码。如果可以,你应该使用它而不是前者。