SQLExpress - How do I set username/password for a sql datafile

若如初见. 提交于 2019-12-04 11:45:35

Add the database ASPNETDB.mdf to the SQL Express with SQL Management studio You can download it from Microsoft web platform installer.

Open SQL Management studio Right click on Databases > Attach > Add the mdf and log file (Preferable you put them somewhere else then the site directory.

In MSSQL you can set the username and password easily, Open SQL Management studio.

Login to the Management studio: Expand Security > Logins > Write Click on Logins "New Login"

Login Name: For example logmein Make it SQL Server Authentication Set the Passwords Remove the Enforce

On the left side you will have the User Mapping Select the Database you want to connect to and give the write permissions, for example if this user can write to the database you will want to make it datawriter or db_owner which is higher permission:

The database built-in roles are:

public – the default set of authorizations

db_owner – allowed to perform any operation of a specified database

db_oddladmin – allowed to create or modify the new objects of the database (so-called DDL operations); you should take notice of the fact that the user doesn’t have to have

db_owner authorizations to do that

db_datareader – allowed to read any table

db_datawriter – allowed to write any table

db_denydatareader – banned to read tables (an overt authorization takeaway)

dDb_denydatawriter – banned to write tables

After you add the database to the SQL: You can add in the web.config

<add name="ASPNETDB" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=ASPNETDB.mdf;User ID=yourusername;Password=yourpassword" providerName="System.Data.SqlClient" />
<add name="Dok " connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dok.mdf;User ID=yourusername;Password=yourpassword" providerName="System.Data.SqlClient" />

or if you prefer to have it in the code like you have it above also it can work.

Regards, Gabriel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!