在SQL 2016中创建数据库在WEB配置文件中添加该连接字符串。
将连接字符串传递到实体框架的SQL连接对象或数据库上下文之后。here is reference link
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WingtipToys;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="WingtipToys" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
,
您可以从web.config文件中更改默认连接,将其打开,转到连接字符串,然后删除默认连接,并在SQL上复制服务器名称连接,然后粘贴连接字符串,然后您可以更改数据库名称
如您在此图中看到的,开始从本地单词中删除默认连接
enter image description here
enter image description here
这是服务器名称连接
,
您可以使用web.config文件更新您的连接字符串
要么
在您的代码中也使用它
using System.Data.SqlClient;
SqlConnection connection = new SqlConnection();
connection.ConnectionString ="Data Source=ServerName;" +"InitialCatalog=DataBaseName;" +
"Integrated Security=SSPI;";
connection.Open();
,
如果您想使用Asp.net身份验证和授权,那么我们不需要创建表自己,而在用户注册后,身份将为我们完成。
登录和授权一起进行。只需在ConnectionString中指定数据库名称,现在您就可以使用DefaultConnection作为ConnectionString键。添加注册一个虚拟用户。您应该在指定的数据库中看到表。
本文链接:https://www.f2er.com/3140036.html