February 17, 2010 at 3:33 pm
Once more we can't connect to the database. We get the age old message:
Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
Login failed for user 'HKRAM\Mark Hardenbergh'. HKRAM is the name of my computer. Mark Hardenbergh is, obviously, me.
Which means to me there is something wrong with my user name. Anybody know what's wrong with my user name? Do I have another name? Where do I find my other name. I understand that I could use sa for my name, but that doesn't work either.
Here is the code written on the default2.aspx.vb page, the code behind page.
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cn As New SqlConnection("C:\DOCUMENTS AND SETTINGS\MARK HARDENBERGH\MY DOCUMENTS\VISUAL STUDIO 2008\WEBSITES\WEBSITE5\APP_DATA\VANILLA.MDF;user id=HKRAM\Mark Hardenbergh")
Dim cmd As New SqlCommand
With cmd
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "mhhtrial"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
End Sub
No doubt everyone can recognize what I am trying to do. I am trying to perform the simple taks of running a stored procedure. It is in a database called vanilla.mdb. And, yes, it exist there. However I can't get to square 1 because the fool thing won't let me connect to vanilla.mdb.
As you can imagine, I have a gridview that finds a table in vanilla.mdb and displays it beautifully. When I do gridviews and have the connection string turning up in web.config, there is no problem.
The connection string that is in the web.config file is:
<add name="VanillaConnectionString" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\Vanilla.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
It certainly would be nice, since this connection string obviously works, if I could use it in the vb in the code behind page. But, so far, no forum wants to explain that, much less any book I have bought.
Can anyone straighten out this Dim cn as New SqlConnection....... out so I can move along?
February 17, 2010 at 4:36 pm
Dim _cnString as string = ConfigurationManager.ConnectionStrings("VanillaConnectionString").ConnectionString
Dim cn As New SqlConnection(_cnString)
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
February 18, 2010 at 10:14 am
Is you Account a Member of the SysAdmin Fixed Server Role or DBOwner or DBReader Database Roles on your machine? I would not recommend this when you promote this to production. I'm suggesting to do this for testing purposes.
Have you tried adding that account to any of these roles or check to see what groups your user account is in.
What is your default Database? If there is an issue with that Database you will not be able to connect and you will get this error.
Then go into SQL Server & check.
When you registered the Server what Account did you use? I assume that you used your Domain Account?
Take the GUI out of the question & try and connect from SSMS.
I hope this helps.:-)
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
February 18, 2010 at 2:31 pm
Where do I look to see if my account is a member of the SysAdmin Fixed Server Role or DBOwner or DBReader Database Roles?
What does test purposes have to do with this? I am writing pages to go on the web for people to interact with.
How do I add the account to the above roles?
How do I find out what groups my user account is in?
Default database? I have a database called vanilla.mdf. Where do I look to see if I have a default database?
What do I check for in SQL Server?
I didn't know I registered the server. As far as I know I have a server called HKRAM\SQLEXPRESS and I don't have any other server.
I am not using my domain account. I am using local host and intend to move the web site, including the database, to the server connected with the web. I'll probably have to change the name of local host to my domain at that time, where ever it might be written.
I'd appreciate any help you can give me.
February 18, 2010 at 3:08 pm
I hope that I'm not giving bad information but I always encourage testing connection issues from SQL to rule it out.
If you go into SSMS you can expand Security at the Server Level. This is where you create Logins. Expand and look at the Logins. You can create a Login. If you create a a user, use your Domain Account.
If you add yourself as a member of the fixed Server role SysAdmin, then you will not need to create a user.
Connect to SQL Server using your Domain Account.
To identify the default Database right click on the Login and select properties.
The default database is on the bottom of the screen.
Open up Query Analyzer or expand the Database & Try & query the Database.
I hope that this helps.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
February 18, 2010 at 4:17 pm
Hi,
Did you try the code I posted?
You said the gridview worked using the connection string in web.config, so there is no problem with authentication, but there is a problem with your manual connection, so try the code...
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply