In order to grant the ASPNET runtime access to your SQL database from the sqlcmd.exe command prompt you need to do the following:
— If permissions exist but are invalid, eg database copied from different machine:
Use mydatabase
Godrop
schema ASPNET
gosp_droprolemember
'db_owner', ASPNET
godrop
user ASPNET
go—Now Add back permissions for this machine:
sp_grantlogin
'MACHINENAME\ASPNET'
gosp_grantdbaccess
'MACHINENAME\ASPNET', 'ASPNET'
goSp_addrolemember
'db_owner', 'ASPNET'
go
Alternatively, use the attached batch file which passes in the correct machine name

And this: sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'