need help with database connection - asp.net

I am facing problem with database connection. As I know if we create new user, using Create UserWizard control and after running it if we refresh the refresh button from solution explorer,aspnetdb.mdf will generated automatically under app directory.But in my case its not happening.I mean aspnetdb.mdf is not generating. Once I submit the sign up submit button getting this error message "Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'. "
Here is my connection string in web.configfile.
<connectionStrings>
<add name="BankingTransaction" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Bank.mdf;integrated security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Please somebody help me where is my mistake.
Thanks,
Masum

The database need the regsql.exe running on it to add all the files the membership .net stuff uses.
This explains how to do it
http://msdn.microsoft.com/en-us/library/ms229862(VS.80).aspx
This installs all the tables and procedures needed for the ASPNET roles and membeship

It sounds like there is a stored procedure you are calling (dbo.aspnet_CheckSchemaVersion) that does not exist in the database.
Here are some folks who seem to have encountered this same issue:
http://forums.asp.net/t/940632.aspx
http://forums.asp.net/p/1042979/1456396.aspx#1456396
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/7a85cf72-7f53-421f-be74-b12262c47f37/
It may be worth trying some of those solutions. This one sounds promising:
Run the following on your SQL SERVER instance:
Exec sp_addrolemember 'aspnet_Membership_FullAccess', 'YourUser'
go
Exec sp_addrolemember 'aspnet_Personalization_FullAccess', 'YourUser'
go
Exec sp_addrolemember 'aspnet_Profile_FullAccess', 'YourUser'
go
Exec sp_addrolemember 'aspnet_Roles_FullAccess', 'YourUser'
go
Exec sp_addrolemember 'aspnet_WebEvent_FullAccess', 'YourUser'
go

Related

web.config connection string to different database server

I have two conn strings in my web.config
The second of them connects to external database - the database is on different server than the current website.
Is it possible?
How do I write my connection string?
I have this now:
<add name="newConn" connectionString="server=www.somedomain.com;database=dbname;user id=dbuser;password=dbpass" providerName="MySql.Data.MySqlClient" />
But I'm getting error saying:
Access denied for user 'dbuser'#'currentdnsserver.com' (using password: YES)
Thanks
You have 2 questions:
Answers:
1. Absolutely.
2. You will need to write a connection string that use TCP/IP as the transport.
To debug this you should try connecting via the SQL Server Mgmt Studio using the credentials you are using in the conn string.
I assume you are using SQL Server, here is a typical connection string to a TCP/IP enabled DBMS using SQL Server authentication.
<add name="conn2" connectionString="Database=myDB;Server=serverNameOrIpAddress;uid=id;pwd=pwd;" providerName="System.Data.SqlClient"/>
The connection I wanted to establish was between different hosting server (one on Windows, another on Linux).
My hosting provider told me it's not possible to connecto from Windows .NET website to Linux MySQL db. Not sure why but not possible.
Would be possible on the same hosting they said.
Thank you for trying to help #T McKeown
Yes, you can connect to remote server and this is used alot.
The main thing that you should edit in your connection string is: Data Source.
Example:
Data Source=192.166.0.2;initial catalog=books;integrated security=False;user id=admin;password=!password1
Data Source: IP or URL of the computer you want to connect
Initial Catalog: Name of the Database you want to use
UserName and Password for the database user you want to use when you working with
the database are required.

Can we delete old records from aspstatetempsessions table?

Recently I created Session State in my project, code is below
<sessionState mode="SQLServer" allowCustomSqlDatabase="true"
sqlConnectionString="Data Source=ADMIN-9F8C57749\SQLEXPRESS;Initial
Catalog=kecbliss;Integrated Security=True" timeout="60"
stateNetworkTimeout="60">
</sessionState>
The problem is day by day aspstatetempsessions table is becoming big
so my question is
Can i delete previous days records from aspstatetempsessions?
How to achieve this without affecting to project ?
Project details
Front end ASP.NET
Back end MS SQL Server
To resolve this issue:
Step1:
Make sure that the SQL Agent service is running and also check to see if the SQL Agent job called SSPdatabaseName_Job_DeleteExpiredSessions exists and run successfully.
If you have the SQL Agent Services is started and the SQL Agent Job is missing, proceed to the Step2
Step2:
Run the DeleteExpiredSessions Stored Procedure manually on the SSP database.
Connect to the database server using Microsoft SSMS --> Client on
New query.
Make sure you have selected the SSP database in the new query
windows.
Type in “EXEC DeleteExpiredSessions” and execute the query.
This command would clean up the ASPStateTempSessions table and not remove any active connections.
Note: Depending on the ASPStateTempSessions table size, it is recommended to run this command during off-peak times on the SharePoint/SQL server.
To register the job to be run automatically in the future follow the below steps:
Ensure the SQL Agent is on (it should be set as an Automatic startup
Windows service as well)
Obtain the SSP database name that contains the ASPStateTempSessions
table missing an associated SQL Agent Job.
Execute the following command on a WFE or any application servers
with the server farm:
From the command prompt get to the ASP .Net folder %WINDIR%\Microsoft.NET\Framework\v2.0.50727\
aspnet_regsql.exe -sqlexportonly exportfilepath.sql -ssadd -sstype c -d SSP db name
Open the exportfilepath.sql file in a note pad, make sure to select
the text between the following lines:
/* Create the job to delete expired sessions */
and
/**********************************/
Copy the above copied test and Execute the code on the SQL box
hosting the SSP database.
Now you should find a SQL Agent Job is created.
Raj
Source: support.microsoft.com/kb/970788

How do I get ELMAH to work with SQL Server (permission problems)

I've got ELMAH working on my (Cassini) development server, and was quite happy with it, but now that I'm trying to move everything to my production server (IIS7), the honeymoon looks like being over.
I've got past the "gotcha" with IIS7, which frankly could have been better highlighted in the documentation, and if I just use the in-memory log then it works.
However, I'm trying to get it to use the SQL Server log (as I do on my development system), and I'm getting an error along the lines of:
The EXECUTE permission was denied on the object ELMAH_GetErrorsXml
Well, fine. I know how to grant database permissions, but I'm really struggling to understand which user and which stored procs/tables I need to grant access to.
The thing that's really confusing me is that I didn't have to do anything like this to get it to work on my development server. The only difference I can see is that on my development server it seems to connect as NT AUTHORITY\IUSR, whereas on my production server it seems to connect as NT AUTHORITY\NETWORK SERVICE. (It's just using a trusted connection so I've not explicitly configured it to do that - I presume it's to do with the web server). UPDATE: I've since established that because I'm using Cassini, it was actually logging in as me (an admin) and not IUSR, which explains why I didn't get any permission problems.
On my development server, the IUSR account is a member of the public database role, and has access to the required database (again as "public"). There's no explicit granting of object-level permissions. [See update above - this is irrelevant].
On my production server, I've added NETWORK SERVICE in exactly the same way (public database role, explicit access to the database as "public"). Yet, I get this permission error. Why?!! [See update above - the only reason I don't get a permission error is because I'm running as an admin].
And, of course, if the fact that it works locally is just "luck", I will need to know which SPs/tables to grant access to. My guess would be all 3 SPs and not the table, but it would be good (again) to see some documentation that makes this explicit.
example of sql needed to give execute permission to the user USER_NAME:
GRANT EXECUTE ON ELMAH_GetErrorsXml TO USER_NAME
GRANT EXECUTE ON ELMAH_GetErrorXml TO USER_NAME
GRANT EXECUTE ON ELMAH_LogError TO USER_NAME
Are you providing ELMAH with a full connectionstring in the web.config? If so, you should know exactly what db user to grant permissions to, right? And yes, permission would be to execute the three ELMAH stored procedures...
Here's a configuration that I've used:
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah" />
</elmah>
<connectionStrings>
<add name="elmah" connectionString="Data Source=XXX;Initial Catalog=XXX;User Id=XXX;Password=XXX;" providerName="System.Data.SqlClient" />
</connectionStrings>

ASP.NET ASPNETDB.MDF Cannot open database

I am using membership class for my user management, and it created a database called ASPNETDB.MDF.. I decided to use the same database to handle my other data, and so I added some of my own tables in there...
When I try to access it:
<connectionStrings>
<add name="connString" connectionString="Initial Catalog=MyProject;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MyName\Documents\Visual Studio 2008\Projects\Project\MyProject\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Using this:
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("connString").ToString)
It gives me this error after I log in through Membership class:
Cannot open database "MyProject" requested by the login. The login failed.
Login failed for user 'My-PC\Myuser'.
I am not sure what's going on?
Edit: If i don't use Membership class, I can use the database fine.. but when after I login using the membership class, it stops to work..
Make sure My-Pc\MyUser has access appropriate permissions to 'MyProject' database. For the test environment that my local projects run on, i generally assign myself as the database owner to the database i want to access. That is if i am the only user accessing it. You can do so by running EXEC sp_changedbowner 'My-Pc\MyUser'. Obviously, you want to dedicate a separate account with limited access for your production environment.
You'll probably need to make sure that the user the web server is running as has read/write access to the db file and directory.
Try removing "connString" from web.config and using "LocalSqlServer" connection string instead (it is defined in machine.config):
Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString)
I also encountered this problem, and I noticed that it does indeed work if I changed the owner of the database to 'My-Pc\MyUser' (via EXEC sp_changedbowner 'My-Pc\MyUser') as pointed out above.
You might also try running this on your database:
exec sp_grantlogin 'My-PC\MyUser2'
This is certainly useful if you want MyUser AND MyUser2 having access to your database. I encountered this scenario when I have to execute aspnet_regsql.exe using MyUser2 credentials (as the owner of my database is ASPNET, which does NOT have login/runas capabilities).
Hope this helps someone :)

working with sql server 2008

I am not used to work with SQL Server(usually I just use express). I run it on windows server 2008, iis7.
I have attached the database to my sql server. I made a web site in iis7 but I get this error message.
Cannot open database "Phaeton.mdf" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Connectionstring I use
<add key="PhaetonConnectionString" value="Data Source=.;Initial Catalog=Phaeton.mdf;Integrated Security=True"/>
Thanks
Since you are using Integrated Security the SQL connection will use the windows identity which is passed from ASP.NET.
You can either change your security to mixed-mode which will involve removing the integrated security. Or use impersonation (check IIS and your web.config) and grant that user access to the database.
Hope that helps
You need to configure your application in IIS to turn off anonymous access and turn on Windows authentication(If yoy want to use integrated security).
Access SQL Server Using Windows Integrated Security
The other way, you can use a connection string with user/password ... with the appropriate login
Problem was that the database I tried to attach was sql express
The problem is here:
Initial Catalog=Phaeton.mdf
In SQL Server Express, you can attach a filename as a local database. That's not how it works on a production SQL Server. In non-Express versions you attach a database permanently, which it looks like you've already done, and you give it a logical name, which is not the same as the primary file name.
I would guess that if the file name was "Phaeton.mdf" then you probably named the database "Phaeton". In which case that part of the connection string should simply be:
Initial Catalog=Phaeton
If that's not the right name, you can get a list of database names from the server using the following script:
USE master;
SELECT name FROM sys.databases

Resources