Complains of a user that does not exist - asp.net

I've specified the user of my application pool to be SERVER4\IUSR_SERVER4. And then I added this user to the SQL Server. But when I try to connect to the database I get the following error:
Server Error in '/BSHHD' Application.
Cannot open user default database. Login failed.
Login failed for user 'SERVER4\Administrator'.
What's driving me mad is there's no user named SERVER4\Administrator. What do I have to do in order to be able to properly connect to this SQL Server database from my website?
P.S. I think this is related with Membership authentication. Now I need to find out how Membership accesses SQL Server and where the login credentials are specified

The thing is, the app pool user is not necessarily the user you use to connect to MSSQL (as a guy in the comments already stated). After seeing your connection string, this is probably the case, and maybe, just maybe, the problem is not the user but it's default database.
I've had this error in the past: Try setting the user you use in the connection string (clerk's) default database to something else. This error is common when you've set a default database for a user before and now the database doesn't exist anymore or is having some problems.
You can change the user's default database using something like this:
Exec sp_defaultdb #loginame='clerk', #defdb='dok'
You can also use something like this but I've never used it:
ALTER LOGIN SQLLogin WITH DEFAULT_DATABASE = AvailDBName
Also, there's no need to set the integrated security to false because it is the default value already. I hope this helps =)

Related

Cannot open database requested by the login .Login failed for user

I have few aspx pages and and few tables in database. Each page connects to respective table. The purpose of each page is the same, only some condition are different. When I develop I use different database for testing data and called it "Database_DEV1" to be easy to remember. Now a problem is that only one page connects to the database (Database_DEV1) with same connection string. Other pages throws error with message:
Cannot open database "Database" requested by the login. The login failed.
Login failed for user 'xxx'
Why does it connect to "Database" if I provided connection string that refers to Database_DEV1?
Is it possible that this kind of error may appear at all? Do I miss something? I checked connection string I provided.
It looks like page "remembers" something different for some reason. I tried simple SqlConnection class and it works, but dbml file not.
update
Problem is that that Context refers to folder:
// C:\Users\xxx\AppData\Local\Temp\Temporary ASP.NET Files\root\0f053840_shadow\2edebf24\5576\App_Code.whnwybua.dll
At first, application connects using context that is declared in dbml. But when I do some actions it tries to connect using context which refers to dll file I described above. Why is that?

Restoring a database into a different instance of tridion

I have got most of the way but there seems to be a permissions issue somewhere:
Before the restore everything is working fine in my target environment - target has a server login account TCMDBUser which is mapped to my tridion_cm database user TCMDBUser
My source tridion_cm database has user TCMDBUser_DEV.
After restoring the source .bak into my target TCMDBUser_DEV is orphaned.
I edit the TRUSTEES table to correct MTSUser and my admin log accounts for my target environment and run the following to fix up my orphaned database user:
sp_change_users_login #Action='update_one',
#UserNamePattern='TCMDBUser_DEV',
#LoginName='TCMDBUser'
GO
I can log back in to Tridion explorer and see the expected list of publications and can walk through the tree structure but when I come to a folder which should contain items I see nothing with error:
and the corresponding event log error is:
Unable to get list of SDL Tridion Content Manager items.
DESCRIPTION
Error Code:
0x80040000 (-2147221504)
Call stack:
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String)
System.Data.SqlClient.SqlDataReader.GetOrdinal(String)
System.Data.SqlClient.SqlDataReader.get_Item(String)
Tridion.ContentManager.Data.AdoNet.DatabaseUtilities.ConvertToFieldDictionary(IDataRecord,IDictionary`2)
Tridion.ContentManager.Data.AdoNet.IdentifiableObjectDataMapper.Read(TcmUri,IDataRecord,IDictionary`2)
Tridion.ContentManager.Data.AdoNet.ContentManagement.OrganizationalItemDataMapper.GetListItemsPost(IDataReader,TcmUri,OrganizationalItemItemsFilterData)
Tridion.ContentManager.Data.AdoNet.ContentManagement.OrganizationalItemDataMapper.Tridion.ContentManager.Data.ContentManagement.IOrganizationalItemDataMapper.GetListItems(TcmUri,OrganizationalItemItemsFilterData)
Tridion.ContentManager.ContentManagement.OrganizationalItem.GetListItemsData(OrganizationalItemItemsFilter)
Tridion.ContentManager.ContentManagement.OrganizationalItem.GetListItemsStream(OrganizationalItemItemsFilter)
Tridion.ContentManager.BLFacade.ContentManagement.OrganizationalItemFacade.GetListItemsXml(UserContext,String,ListFilter,ListColumnFilter)
Tridion.ContentManager.BLFacade.ContentManagement.OrganizationalItemFacade.GetListData(UserContext,String,EnumListKind,ListColumnFilter,String)
Folder.GetListItems
You will need to delete/drop the TCMDBUser_DEV form the DB and then create a new one with the same name and password (or reattach it to your cm DB). That should fix your problem.
I normally use the delete method with MS SQL server. I believe this occurs due to the ownership status that the TCMDBUser has on the database Schema.
When complete your TCMDBUser user should have the following permissions on your Tridion_CM database
Like Chris mentioned, I always drop the user from the database and then assign the existing TCMDBUser in SQL Server the rights to the restored database. You can drop the user with the following command (on the restored database):
EXEC sp_dropuser TCMDBUser
Then through the SQL Server - Security - Logins, you request the properties of your TCMDBUser and in the User Mapping add the following database roles: db_datareader, db_datawriter and db_ddladmin.
That's what I've always done in the past and works for me, not sure if its all required, but worth a try I guess
Try creating new user TCMDBUser in the database and run the following command
EXEC sp_change_users_login 'Update_One', 'TCMDBUser', 'TCMDBUser'

get session variable in runtime

There are more web applications (asp.net 4) in own virtual directory of IIS server (under win2003).
And appertain to all own schema and account in oracle 11g database.
After login all users have some session variables (like username,shema name ...etc). I want to get these information for user management in runtime. How can I ask it from the server?
Maybe you are looking for this?
To retrieve:
string username = Session["Username"];
To put things on Session:
Session["Username"]="SomeValue";

Using Access database for webpage, concurrent user issues

I have a simple access database that resides on a network drive. All of the people that need to make any modifications to this database have access on their machine, but they would like to have a read-only website just displaying the data contained in it. I set up a website and tried using the accessdatasource, and while I could connect, it had issues whenever a user had the database open in access. I swapped to using a sqldatasource with a connection string set up according to www.connectionstrings.com, but I seem to be having either the same or similar issues, depending on how I set up the string/database. Basically, the entire issue is, if the database is opened by any user, the webpage is prevented from opening the database. Is it possible to open the database read only from the webpage?
It is an access 2000 database, but everyone is using copies of access 2007, and in all of these instances, the ASP.NET user has read/write access to the network directory containing the database, and read access to the database itself.
When I use the connection string:
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\<source>\<database>.mdb;User Id=<USER>;Password=<PASSWORD>;Mode=Share Deny Write;"
Where is not the default "admin" user, and is configured to have open/run (not open/exclusive) permissions on the database, I get the error:
Cannot start your application. The workgroup information file is missing or opened exclusively by another user.
As far as I can tell, there is no workgroup information file, but I am not really sure what I am doing there.
When is the default "admin" user, I get the error:
Could not use ''; file already in use.
If someone has the database currently open, otherwise, it works fine.
And finally, if I use the connection string:
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\<source>\<database>.mdb;User Id=<USER>;Password=<PASSWORD>;Mode=Read;"
I get the error:
Could not lock file.
I have been googling this for the past several days now and I feel like I've just been going around in circles. Any insight at all would be appreciated.
As it's Access 2000 format there will definately have to be a workgroup file (.mdw) even if that has no security set as such. I would try the connection string whereby you also specify the workgroup location e.g:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:System Database=system.mdw;User ID=myUsername;Password=myPassword;
Furthermore, I wouldn't recommend setting the read/write properties in the connection string, instead I think you would be better to create an account in the workgroup file and only assign it read only priviledges.
Update:
This is the ODBC connection method:
Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;

How can I create a database on my server from the web?

I have an admin account for my website where I add new clients. When a new client is added, they get an account and their own database.
The problem is I can't create new databases on my server from my admin account. When running it locally, I can add a database locally. But, when I try adding to the server running my website off the server, I get
CREATE DATABASE permission denied in database 'master'.
I've been able to add the database (locally) a few ways. This is one of the simpler working versions:
tmpConn.ConnectionString = "Data Source=.\\SQLEXPRESS; DATABASE = master;Integrated Security=True;";
sqlCreateDBQuery = " CREATE DATABASE " + dbname;
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{}
I suspect that whatever account you're using to connect to Sql Server doesn't have permissions to CREATE DATABASE. You're probably using Integrated Security, which would use Network Service/ASP.NET to connect to MSSQL. You need to create a new connection string that uses Sql Authentication with sa (or another sysadmin) credentials.
Oh - and this would work locally because you're running it under Visual Studio's WebDev.exe which is run with your local user account - which is probably set up as a sysadmin in MSSQL.
You should contact your service provider. (Or the maintainer of the server).
You need create database and create database user permissions. Your service provider should be able to facilitate this.
Something else no one has suggested is what kind of validation you are doing on the dbname value. Are you sure there are no spaces in it? That it's not a reserved word? That it doesn't contain malicious code? At very least you should encase it in brackets:
sqlCreateDBQuery = String.Format(" CREATE DATABASE [{0}]", dbname);
I really hope you aren't allowing the user to type this name directly into a textbox somewhere. Even if you use property security on the initial input and this is pulled back from a common "clients" db of some kind, you might be setting yourself up for a 2nd order Sql Injection vulnerability.
After you've addressed that, we can look at the error message here. In this case, the problem is that your web user does not have appropriate CREATE permissions. You need to correct that and it should allow you to proceed. You probably want to reserve a special account for this that you switch to just at this time, so your application doesn't normally run in a context that would allow this kind of action.
Check the permissions for MySQL: Does your admin account have different settings for a local connection versus any host?

Resources