连接到SQL Server DB [英] Connecting to SQL Server DB
问题描述
大家好,
从aspx文件连接到SQL Server
数据库时,我遗漏了一些东西,可能是愚蠢的。我没有真正做过多的SQL服务器和
怀疑这是一个问题。我已在本地安装了SQL Server
开发人员版,并且有一个pubs数据库。
我正在尝试的连接如下:
SqlConnection objConnection =
new SqlConnection(" server = localhost; database = pub; uid = sa; pwd = admi n");
试试
{
//打开连接。
objConnection.Open();
/ * snip * /
}
catch(例外情况)
{
ErrorMessage。 Text = ex.Message.ToString();
}
捕获的异常表明('sa''是否为uid我''我试图
连接):
用户''sa''登录失败。原因:与可信SQL Server无关
连接。 (仅限Windows身份验证)或
用户sa登录失败。 (Windows和SQL Server身份验证)
我已经能够通过VFP创建连接(尽管使用ODBC)。
它创建的连接字符串是:
DSN = SQLServer1; UID = sa; PWD = admin; APP = Microsoft Visual FoxPro; WSID = J2K,
向我表明sa / admin登录是正确的(这是我在
安装的地方)。
有什么想法吗?
TIA,
John
Hi all,
I''m missing something, probably stupid, on connecting to a SQL Server
database from an aspx file. I haven''t really done much w/ SQL Server and
suspect that it''s a problem on that side. I''ve installed the SQL Server
developer edition locally and do have a pubs database.
The connection I''m attempting is the following:
SqlConnection objConnection =
new SqlConnection( "server=localhost;database=pub;uid=sa;pwd=admi n" );
try
{
// Open the connection.
objConnection.Open();
/*snip*/
}
catch( Exception ex )
{
ErrorMessage.Text = ex.Message.ToString();
}
The exception caught indicates (whether or not ''sa'' is the uid I''m trying to
connect with):
Login failed for user ''sa''. Reason: Not associated with a trusted SQL Server
connection. (w/Windows-only Authentication) or
Login failed for user ''sa''. (Windows and SQL Server Authentication)
I have been able to create a connection through VFP (though using ODBC).
The connection string it creates is:
DSN=SQLServer1;UID=sa;PWD=admin;APP=Microsoft Visual FoxPro;WSID=J2K, which
indicates to me that the sa/admin login is correct (which is what Iset at
installation).
Any ideas?
TIA,
John
推荐答案
> DSN = SQLServer1;
如何配置DSN = SQLServer1?它是否使用名称localhost;或者
是否使用实际的计算机名称或IP地址?你确定1433号港口设置了
吗?
-
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
> DSN=SQLServer1;
How is this DSN=SQLServer1 configured? Does it use the name "localhost" or
does it use an actual computer name, or IP address? Are you sure it''s set
for port 1433?
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
交叉发布不好。
是localhost和SQLServer1实际上是同一台机器?如果没有,那么你在本地主机仅限Windows上进行
身份验证吗?尝试一些这些连接
字符串
" server = yourIPaddressHere; database = pubs; uid = sa; pwd = admin;"
" server = yourIPaddressHere; database = pubs; integr ated security = sspi;"
" server = localhost; database = pubs; integrated security = sspi;"
" server = SQLServer1; database = pubs; integrated security = sspi;"
" server =(local); database = pubs; uid = sa; pwd = admin;" ;
" server =(local); database = pubs; integrated security = sspi;"
" server =。; database = pubs; uid = sa; pwd = admin;"
" server =。; database = pubs; integrated security = sspi;"
hth
Eric
" John Spiegel" < JS ****** @ YETANOTHERSPAMHATERc-comld.com>在消息中写道
新闻:eX *************** @ TK2MSFTNGP11.phx.gbl ...
Cross-posting is bad.
Is "localhost" and "SQLServer1" actually the same machine? If not, is your
authentication on localhost "windows only"? Try some these connection
strings
"server=yourIPaddressHere;database=pubs;uid=sa;pwd =admin;"
"server=yourIPaddressHere;database=pubs;integr ated security=sspi;"
"server=localhost;database=pubs;integrated security=sspi;"
"server=SQLServer1;database=pubs;integrated security=sspi;"
"server=(local);database=pubs;uid=sa;pwd=admin ;"
"server=(local);database=pubs;integrated security=sspi;"
"server=.;database=pubs;uid=sa;pwd=admin;"
"server=.;database=pubs;integrated security=sspi;"
hth
Eric
"John Spiegel" <js******@YETANOTHERSPAMHATERc-comld.com> wrote in message
news:eX***************@TK2MSFTNGP11.phx.gbl...
大家好,<从aspx文件连接到SQL Server数据库时,我遗漏了一些东西,可能是愚蠢的。我没有真正做过多的SQL Server和
怀疑这是一个问题。我已在本地安装了SQL Server
开发人员版,并且有一个pubs数据库。
我正在尝试的连接如下:
SqlConnection objConnection =
新的SqlConnection(
" server = localhost; database = pub; uid = sa; pwd = admi n");
尝试
{
//打开连接。
objConnection.Open();
/ * snip * /
}
catch(Exception ex)
{
ErrorMessage.Text = ex.Message.ToString();
}
捕获的异常表明('sa''是否是我正在尝试
连接的uid) :
用户''sa''登录失败。原因:与受信任的SQL
服务器连接无关。 (仅限Windows身份验证)或
用户sa登录失败。 (Windows和SQL Server身份验证)
我已经能够通过VFP创建连接(虽然使用ODBC)。
它创建的连接字符串是:
DSN = SQLServer1; UID = sa; PWD = admin; APP = Microsoft Visual FoxPro; WSID = J2K,
表示sa / admin登录是正确的(这是安装时的设置)。
任何想法?
TIA,
John
Hi all,
I''m missing something, probably stupid, on connecting to a SQL Server
database from an aspx file. I haven''t really done much w/ SQL Server and
suspect that it''s a problem on that side. I''ve installed the SQL Server
developer edition locally and do have a pubs database.
The connection I''m attempting is the following:
SqlConnection objConnection =
new SqlConnection( "server=localhost;database=pub;uid=sa;pwd=admi n" );
try
{
// Open the connection.
objConnection.Open();
/*snip*/
}
catch( Exception ex )
{
ErrorMessage.Text = ex.Message.ToString();
}
The exception caught indicates (whether or not ''sa'' is the uid I''m trying to connect with):
Login failed for user ''sa''. Reason: Not associated with a trusted SQL Server connection. (w/Windows-only Authentication) or
Login failed for user ''sa''. (Windows and SQL Server Authentication)
I have been able to create a connection through VFP (though using ODBC).
The connection string it creates is:
DSN=SQLServer1;UID=sa;PWD=admin;APP=Microsoft Visual FoxPro;WSID=J2K, which indicates to me that the sa/admin login is correct (which is what Iset at
installation).
Any ideas?
TIA,
John
谢谢你,亚伦。对于我的新手无知而提前抱歉...
DSN是一个系统DSN,配置为连接到服务器J2K。 (这是计算机名称和SQL Server的名称),使用TCP / IP
网络库来动态确定端口(但是,是的,默认的
端口是1433)。我无法在DSN中找到对localhost的任何引用。
BTW,我不认为ADO连接正在尝试使用DSN(但是
可能完全误解了一些事情。)
- John
默认端口是1433.
Aaron Bertrand - MVP < AA *** @ TRASHaspfaq.com>在消息中写道
新闻:#S ************** @ tk2msftngp13.phx.gbl ...
Thanks, Aaron. And sorry in advance for my newbie ignorance...
The DSN is a system DSN, configured as connecting to server "J2K" (which is
the name of the computer as well as of the SQL Server), using the TCP/IP
network library set to dynamically determine port (but, yes, the default
port is 1433). I can''t find any reference to localhost in the DSN.
BTW, I don''t think the ADO connection is attempting to use the DSN (but
could be COMPLETELY misinterpreting things).
- John
The default port is 1433.
"Aaron Bertrand - MVP" <aa***@TRASHaspfaq.com> wrote in message
news:#S**************@tk2msftngp13.phx.gbl...
DSN = SQLServer1;
如何配置此DSN = SQLServer1?它是使用名称localhost
DSN=SQLServer1;
How is this DSN=SQLServer1 configured? Does it use the name "localhost"
还是使用实际的计算机名称或IP地址?你确定它已经设置了1433端口吗?
- Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
这篇关于连接到SQL Server DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!