问题描述
求救求救~~TT谢谢!~Web.config里写的是:<?xmlversion="1.0"?><!--有关如何配置ASP.NET应用程序的详细信息,请访问http://go.microsoft.com/fwlink/?LinkId=169433--><configuration><connectionStrings><addname="LoveAspNet"connectionString="IntegratedSecurity=true;database=LoveAspNet;server=."/></connectionStrings><system.web><compilationdebug="true"targetFramework="4.0"/></system.web></configuration>DBHelper.cs里写的是:stringconnString="";publicDBHelper(){connString=WebConfigurationManager.ConnectionStrings["LoveAspNet"].ConnectionString;}publicSqlDataReaderSelect(stringsql){SqlConnectionconn=newSqlConnection(connString);conn.Open();SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReaderdr=cmd.ExecuteReader(CommandBehavior.CloseConnection);//CommandBehavior.CloseConnection);returndr;}在页面文件中写的是:stringsql="select*fromUserwhereUserName='"+txtName.Text.Trim()+"'";DBHelperdb=newDBHelper();SqlDataReaderdr=db.Select(sql);连接的时候显示的是:用户代码未处理System.Data.SqlClient.SqlExceptionMessage=无法打开登录所请求的数据库"LoveAspNet"。登录失败。用户'thinkpad-THINKthinkpad'登录失败。Source=.NetSqlClientDataProviderErrorCode=-2146232060Class=11LineNumber=65536Number=4060Procedure=""Server=.State=1StackTrace:在System.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception,BooleanbreakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()在System.Data.SqlClient.TdsParser.Run(RunBehaviorrunBehavior,SqlCommandcmdHandler,SqlDataReaderdataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObjectstateObj)在System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(BooleanenlistOK)在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfoserverInfo,StringnewPassword,BooleanignoreSniOpenTimeout,TimeoutTimertimeout,SqlConnectionowningObject)在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfoserverInfo,StringnewPassword,BooleanredirectedUserInstance,SqlConnectionowningObject,SqlConnectionStringconnectionOptions,TimeoutTimertimeout)在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnectionowningObject,TimeoutTimertimeout,SqlConnectionStringconnectionOptions,StringnewPassword,BooleanredirectedUserInstance)在System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentityidentity,SqlConnectionStringconnectionOptions,ObjectproviderInfo,StringnewPassword,SqlConnectionowningObject,BooleanredirectedUserInstance)在System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptionsoptions,ObjectpoolGroupProviderInfo,DbConnectionPoolpool,DbConnectionowningConnection)在System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionowningConnection,DbConnectionPoolpool,DbConnectionOptionsoptions)在System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionowningObject)在System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionowningObject)在System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnectionowningObject)在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnectionowningConnection)在System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnectionouterConnection,DbConnectionFactoryconnectionFactory)在System.Data.SqlClient.SqlConnection.Open()在DBHelper.Select(Stringsql)位置e:WebSite4App_CodeDBHelper.cs:行号32在index.btnEnter_Click(Objectsender,EventArgse)位置e:WebSite4index.aspx.cs:行号27在System.Web.UI.WebControls.Button.OnClick(EventArgse)在System.Web.UI.WebControls.Button.RaisePostBackEvent(StringeventArgument)在System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(StringeventArgument)在System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandlersourceControl,StringeventArgument)在System.Web.UI.Page.RaisePostBackEvent(NameValueCollectionpostData)在System.Web.UI.Page.ProcessRequestMain(BooleanincludeStagesBeforeAsyncPoint,BooleanincludeStagesAfterAsyncPoint)InnerException:我应该怎么做啊???TT谢谢
解决方案
解决方案二:
IntegratedSecurity=true;database=LoveAspNet;server=.换个用户试试DataSource=.;InitialCatalog=LoveAspNet;Userid=sa;pwd=你的sa用户密码
解决方案三:
引用1楼terminator_lzq的回复:
IntegratedSecurity=true;database=LoveAspNet;server=.换个用户试试DataSource=.;InitialCatalog=LoveAspNet;Userid=sa;pwd=你的sa用户密码
建议是指定用户跟密码访问
解决方案四:
看看你SQLSERVER的服务是否启动??
解决方案五:
给你个建议啊:首先检查sql服务器是否启动了!然后呢,在检查一下你的连接字符串是否有问题,上面有跟你说怎么用的了,就不用我说的了,如果连接字符创没有问题,那就可能是你连接字符串中的数据库实例不对
解决方案六:
偶用这样的串连着很正常:<connectionStrings><addname="sqlserver"connectionString="userid=sa;password=123;database=mydb;server=(local)"/></connectionStrings>
解决方案七:
引用1楼terminator_lzq的回复:
IntegratedSecurity=true;database=LoveAspNet;server=.换个用户试试DataSource=.;InitialCatalog=LoveAspNet;Userid=sa;pwd=你的sa用户密码
将server=.换成server=(local)试试
解决方案八:
<connectionStrings><addname="SQLCONNECTIONSTRING"connectionString="datasource=TANSY-PCSQLEXPRESS;uid=sa;pwd=888;database=BOCSCTEST"providerName="System.Data.SqlClient"/></connectionStrings>注:TANSY-PCSQLEXPRESS是我的数据库服务器名称冒死把我的密码都给出啦,
解决方案九:
调试一下!
解决方案十:
将server=.换成server=(local)试试