Showing posts with label learn. Show all posts
Showing posts with label learn. Show all posts

Friday, March 30, 2012

HELP!! SQL Server Express 2005 engine connection to my DB

Preface, I am just starting to learn about database and web development.

I installed VS.net 2005 which updated my web site project file and automatically attached it to a database. It connected to ".\app_data\aspnetdb.mdf". However it messed something up and the connection didn't work. If I create a project from scratch, it connects to its DB just fine, but not my upgraded project.

However, when I publish my web site, I need to use ODBC. So, my thought was to simply set up the system locally in a way that will make it easy to connect on the web site. I was told to add a system DSN to the "Microsoft ODBC Administrator". I tried to add a "SQL Server" and give it the database name but it failed to connect.

So, then I ran the SQL Server Configuration Manager and looked at the server properties and found this string under the advanced -> startup parameters.."-dc:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-ec:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lc:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf"

My database is in an entirely different folder. The database it looks like it is servicing is a "master.mdf" database installed under the SQL server install folder. So, I figured that I found my problem. I just have to change this file to map to mine. I replaced these three strings with paths to my aspnetdb.mdf/ldf files, and created a LOG folder. Howwever, it wasn't able to connect to this database. It said something like "it doesn't exist or you don't have permission", even though I gave it the right path.

So, I'm at a loss for how to get my application to be able to use the ODBC interface to connect to its very own database on my local system.

What do I need to do? Please help!

You need to create a Windows Authentication account on the server for ASPNET with a password.

When an .aspx page loads and tries to access the server, it uses Windows Authentication unless you code the connectionstring to use SQL authentication.

After you create the ASPNET Account, make your connection string look like this:

connectionString="Data Source=ODC01;Initial Catalog=OEM;Integrated Security=True"

Adamus

|||

Thanks you for the feedback. Unfortunately I'm still a bit confused. My problem is that I don't have a complete picture of how this is supposed to work.

Are you saying that I must set up a the server to use an account that uses Windows Authentication before I can attach it to my own MDB file? In other words, it will only connect to the default master.mdb file until I create an account?

Also, using "local" or "system" isn't good enough, I have to specify a user account even on my own personal computer running XP? I am the only one who uses this system, and there is no windows server running on the network. This is my home setup.

This is the map that I understand. There are 3 connections that must be made for this to work.

mydb.mdb --1 (get server to serve my DB)--> SQL Server express 2005 --2 (tell ODBC about my DB exposed by the server)--> ODBC --3 (using the connection string)--> Website.

Right now I beleive none of the 3 connections are working, and I feel like I need to get the step 1 done before I can establish and verify step 2 and then finally use the connection string in step 3.

Are you saying that I must create a Windows Authentication user account before step 1 will work? Does that simply meen that I create a user called "SQL Server" with minimal access on the computer and log into it whenever I want it to connect?

Is there a "complete idiots guide to establishing a SQL server 2005 connection from your web site to your database" book that I could buy?

|||

I take it all back. You were right. Now I understand. I actually had the account set up correctly on the server side, but I wasn't logging in correctly.

Second, when I tried to attach the server to ODBC I was using my computer name alone, when I needed to use <computer_name>\SQLExpress.

Now I have to figure out the connection string. But I am finally over my biggest hurdle. Thanks!

HELP!! SQL Server Express 2005 engine connection to my DB

Preface, I am just starting to learn about database and web development.

I installed VS.net 2005 which updated my web site project file and automatically attached it to a database. It connected to ".\app_data\aspnetdb.mdf". However it messed something up and the connection didn't work. If I create a project from scratch, it connects to its DB just fine, but not my upgraded project.

However, when I publish my web site, I need to use ODBC. So, my thought was to simply set up the system locally in a way that will make it easy to connect on the web site. I was told to add a system DSN to the "Microsoft ODBC Administrator". I tried to add a "SQL Server" and give it the database name but it failed to connect.

So, then I ran the SQL Server Configuration Manager and looked at the server properties and found this string under the advanced -> startup parameters.."-dc:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-ec:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lc:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf"

My database is in an entirely different folder. The database it looks like it is servicing is a "master.mdf" database installed under the SQL server install folder. So, I figured that I found my problem. I just have to change this file to map to mine. I replaced these three strings with paths to my aspnetdb.mdf/ldf files, and created a LOG folder. Howwever, it wasn't able to connect to this database. It said something like "it doesn't exist or you don't have permission", even though I gave it the right path.

So, I'm at a loss for how to get my application to be able to use the ODBC interface to connect to its very own database on my local system.

What do I need to do? Please help!

You need to create a Windows Authentication account on the server for ASPNET with a password.

When an .aspx page loads and tries to access the server, it uses Windows Authentication unless you code the connectionstring to use SQL authentication.

After you create the ASPNET Account, make your connection string look like this:

connectionString="Data Source=ODC01;Initial Catalog=OEM;Integrated Security=True"

Adamus

|||

Thanks you for the feedback. Unfortunately I'm still a bit confused. My problem is that I don't have a complete picture of how this is supposed to work.

Are you saying that I must set up a the server to use an account that uses Windows Authentication before I can attach it to my own MDB file? In other words, it will only connect to the default master.mdb file until I create an account?

Also, using "local" or "system" isn't good enough, I have to specify a user account even on my own personal computer running XP? I am the only one who uses this system, and there is no windows server running on the network. This is my home setup.

This is the map that I understand. There are 3 connections that must be made for this to work.

mydb.mdb --1 (get server to serve my DB)--> SQL Server express 2005 --2 (tell ODBC about my DB exposed by the server)--> ODBC --3 (using the connection string)--> Website.

Right now I beleive none of the 3 connections are working, and I feel like I need to get the step 1 done before I can establish and verify step 2 and then finally use the connection string in step 3.

Are you saying that I must create a Windows Authentication user account before step 1 will work? Does that simply meen that I create a user called "SQL Server" with minimal access on the computer and log into it whenever I want it to connect?

Is there a "complete idiots guide to establishing a SQL server 2005 connection from your web site to your database" book that I could buy?

|||

I take it all back. You were right. Now I understand. I actually had the account set up correctly on the server side, but I wasn't logging in correctly.

Second, when I tried to attach the server to ODBC I was using my computer name alone, when I needed to use <computer_name>\SQLExpress.

Now I have to figure out the connection string. But I am finally over my biggest hurdle. Thanks!

Sunday, February 19, 2012

Help with update forms

Hey Guys
Still very new to asp/sql but trying to learn stuff as I go along.
I'm trying to create an update form where it pulls in an existing record, I
can update it, then submit the changes.
The problem i'm having is when i click to update the record I get this error
message
Cannot update identity column 'id'
In the update form, the ID column is hidden, so i'm not trying to change
that.
How do I get around it?
Thanks for your help.
RichHow are you performing the update? Can you post the actual SQL Statement?
You can't update an IDENTITY column.
David Portas
SQL Server MVP
--|||Hi David
Here's the statement - it was done through dreamweaver, so the code probably
isn't as neat as it should be.
' *** Update Record: set variables
If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <>
"") Then
MM_editConnection = MM_musicone_STRING
MM_editTable = "dbo.m1_web_content"
MM_editColumn = "id"
MM_recordId = "" + Request.Form("MM_recordId") + ""
MM_editRedirectUrl = "articleupdated.asp"
MM_fieldsStr =
" id|value|Publish_Date|value|Section|valu
e|Section_Type|value|Title|value|In
tro|value|Full_Text|value|LiveDate|value
|HyperLink|value|ImageSrc|value|Live
|value"
MM_columnsStr =
" id|none,none,NULL|Publish_Date|',none,NU
LL|Section|',none,''|Section_Type|'
,none,''|Title|',none,''|Intro|',none,''
|Full_Text|',none,''|LiveDate|',none
,NULL|HyperLink|',none,''|ImageSrc|',non
e,''|Live|none,1,0"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "")
Then
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " &
MM_recordId
If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
Any advice would be appreciated!
Thanks
Rich
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:zOKdnaCOHNU1EQ7fRVn-gA@.giganews.com...
> How are you performing the update? Can you post the actual SQL Statement?
> You can't update an IDENTITY column.
> --
> David Portas
> SQL Server MVP
> --
>|||It looks like your UPDATE statement is attempting to update every column (in
the FOR loop). Aside from the specific problem you are having this seems
like a very error-prone and inefficient implementation. In general, avoid
generating SQL dynamically in code. Put your data access code in stored
procs and pass parameters from ASP to the proc. I'm not an ASP expert but
here's someone who is and has some tips and examples of good practices in
ASP:
http://www.aspfaq.com/show.asp?id=2201
http://www.aspfaq.com/show.asp?id=2424
David Portas
SQL Server MVP
--|||Thanks David, some really useful info that - much appreciated.
Richard
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:vaqdnR2tCdwjAg7fRVn-gA@.giganews.com...
> It looks like your UPDATE statement is attempting to update every column
> (in the FOR loop). Aside from the specific problem you are having this
> seems like a very error-prone and inefficient implementation. In general,
> avoid generating SQL dynamically in code. Put your data access code in
> stored procs and pass parameters from ASP to the proc. I'm not an ASP
> expert but here's someone who is and has some tips and examples of good
> practices in ASP:
> http://www.aspfaq.com/show.asp?id=2201
> http://www.aspfaq.com/show.asp?id=2424
> --
> David Portas
> SQL Server MVP
> --
>