Groups | Blog | Home
all groups > sql server connect > september 2005 >

sql server connect : Can't Connect


Jim Bunton
9/19/2005 11:44:58 AM
Win 2000, sqlServer 2000 Personal edition

Trying ot connect using .asp Vb Script

1. Sql server set to use Windows Authentication
2. Log onto Windows 2000 as Jim Bunton {no password)
3 Server 'Study' running ok
4. sql query analyser
i. "SELECT User_Name > dbo
ii. [using database NorthWind]
"SELECT * FROM Customers" > gives expected result

5. VB script
** BEGIN CODE connect.asp ***
<%
@ LANGUAGE="VBSCRIPT"
%>

<%
Option explicit
response.expires = 0
%>

<!-- #include file="adovbs.inc" -->

<html>
<head>
<title></title>
</head>
<body>
<%
dim Cn, CnStr
Set Cn = Server.CreateObject("ADODB.Connection")
Cn.ConnectionTimeOut = 1
Cn.provider="sqloledb"
response.write "Conn Provider is " & Cn.provider
CnStr="Data Source=Study;Initial Catalog=Norhwind;User
Id=sa;Password=;"
' Tried all sorts of user id's and paswords

'CnStr="Data Source=Study;Initial Catalog=Norhwind;User Id = 'Jim
Bunton';Password=;"
'CnStr="Data Source=Study;Initial Catalog=Norhwind;User Id
=dbo;Password=;"
'CnStr="Data Source=Study;Initial Catalog=Norhwind;User Id =
JimBunton;Password=;"
'CnStr="Data Source='Study';Initial Catalogue='Norhwind';User Id
='Study\Jim Bunton';Password=;"
%>
<p>----------</p>
<%
response.write "Cnstr = " & CnStr
'ERROR ALWAYS OCCURS ON NEXT LINEon the next line
Cn.open CnStr
%>
<p>----------</p>
<%
response.write "The End - ran ok"
%>

</body>

</html>

**** END CODE *****

? what to do??
?? am I missing something 'obvious' out ???

--


Jim Bunton



Sue Hoegemeier
9/19/2005 9:06:43 PM
If you are using windows authentication (also known as a
trusted connection) to connect, you don't supply a user
name, password in the connection string. Instead, you
indicate this by using Integrated Security=SSPI
in your connection string.
You also want to make sure the database is correct. In your
examples, you want to make sure you use Northwind (you have
Norwind listed).
You can find sample connection strings using the SQL Server
OLE DB provider at:
http://www.carlprothman.net/Default.aspx?tabid=87#OLEDBProviderForSQLServer

-Sue

On Mon, 19 Sep 2005 11:44:58 GMT, "Jim Bunton"
[quoted text, click to view]
Jim Bunton
9/20/2005 10:17:50 AM
Thanks for your clear response Sue.

Unfortunately I still have a problem:

The following works:-
<%
dim Cn, SqlStr,rsCustomers
Set Cn=3DServer.CreateObject("ADODB.Connection")
Cn.Provider =3D "sqloledb"
Cn.Properties("Data Source") =3D "Study\StudySQLServer"
Cn.Properties("Initial Catalog") =3D "NorthWind"
Cn.Properties("Connect Timeout") =3D "3"
Cn.Properties("User ID") =3D "sa"
Cn.Properties("Password") =3D "mypassword"
Cn.open=20
. . . code which displays Customer info

The folowing does NOT:-
<%
dim Cn, CnStr, SqlStr,rsCustomers
Set Cn=3DServer.CreateObject("ADODB.Connection")
CnStr=3D"Provider=3Dsqloledb;" & _
"Data Source=3DStudy\StudySqlServer;" & _
"Initial Catalog=3DNorthWind;" & _
"Integrated Security=3DSSPI"
response.write "cnStr =3D " & cnStr
' response.end
Cn.open CnStr

It fails at Cn.open CnStr
Error Type:
(0x80040E4D)
/MyWebs/Connect_wAuth.asp, line 15

response.write "cnStr =3D " & cnStr gives:-
cnStr =3D Provider=3Dsqloledb;Data Source=3DStudy\StudySqlServer;Initial =
Catalog=3DNorthWind;Integrated Security=3DSSPI

In Query Analyser (login using Windows Authentification)
select user_Name() >> dbo
select * from Customers >> a list of customers



[quoted text, click to view]
http://www.carlprothman.net/Default.aspx?tabid=3D87#OLEDBProviderForSQLSe=
rver
[quoted text, click to view]
Sue Hoegemeier
9/20/2005 6:55:01 PM
Then it's likely the authentication settings on the IIS side
of it. Try adding the IUSR account as a login in SQL Server
with the appropriate permissions as needed for your code.
Also, turned on failed login audits in SQL Server and
restart the instance. That will help you track down what
login is failing.

-Sue

On Tue, 20 Sep 2005 10:17:50 GMT, "Jim Bunton"
[quoted text, click to view]
AddThis Social Bookmark Button