请教一个连接sqlserver数据库连接错误的解决方法

jiangchuandong 2004-03-28 11:43:07
webconfig里是这样写的
<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the documentation about
debugging ASP .NET files.
-->
<compilation defaultLanguage="c#" debug="true" />
<!-- CUSTOM ERROR MESSAGES
Set customError mode values to control the display of user-friendly
error messages to users instead of error details (including a stack trace):

"On" Always display custom (friendly) messages
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not running
on the local Web server. This setting is recommended for security purposes, so
that you do not display application detail information to remote clients.
-->
<customErrors mode="RemoteOnly" />
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are "Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Windows" />
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page within an application.
Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
trace information will be displayed at the bottom of each page. Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your web application
root.
-->
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20" />
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="Session["ConnStr"].ToString ()" value="" />
</appSettings>
</configuration>
我现在想连接内网的192.168.1.106这台数据库我把data source=127.0.0.1改为192.168.1.106为什么会有错误(在192.168.1.106这台能运行)
...全文
159 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Seeko0 2004-03-29
  • 打赏
  • 举报
回复
没有看家你在appSettings中进行设置啊,你可以增加一个键值
<appSettings>
<add key="Constr" value="data source=192.168.1.106;user id=sa;password=";>
</appSettings>

如果你修改了<sessionState >中的 data source =192.168.1.106;那是不行的,只是表示将Session 存在 192.168.1.106这个服务器上
barrytam 2004-03-29
  • 打赏
  • 举报
回复
<add key="Constr" value="data source=192.168.1.106;user id=sa;password=";>
改为
<add key="Constr" value="data source=192.168.1.106;user id=sa;password=" />
barrytam 2004-03-29
  • 打赏
  • 举报
回复
你那台在192.168.1.106的数据库有没有sa这个用户?没有就作适当修改
jiangchuandong 2004-03-29
  • 打赏
  • 举报
回复
不行呀,好象还是有错误

Parser Error Message: The ';' character, hexadecimal value 0x3B, cannot begin with a name. Line 53, position 74.

Source Error:
Line 51: <!-- Example: <add key="settingName" value="settingValue"/> -->
Line 52: <appSettings>
Line 53: <add key="Constr" value="data source=192.168.1.106;user id=sa;password=";>
Line 54: </appSettings>
Line 55:

wudixiaocaoren 2004-03-29
  • 打赏
  • 举报
回复
是不是因为换行了,你的代码在两行中了:<appSettings>
<add key="Constr" value="data source=192.168.1.106;user id=sa;password=";>
</appSettings>
shooper 2004-03-29
  • 打赏
  • 举报
回复
m_ConnStr = "server=" + m_DataSource + ";database=" + m_Catalog + ";uid=" + m_UserName + ";pwd=" + m_Password + ";";

==>
m_ConnStr = "server=" + m_DataSource + ";database=" + m_Catalog + ";uid=" + m_UserName + ";pwd=" + m_Password ;

试试,顶
jiangchuandong 2004-03-29
  • 打赏
  • 举报
回复
Server Error in '/sqlserver' Application.
--------------------------------------------------------------------------------

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The ';' character, hexadecimal value 0x3B, cannot begin with a name. Line 53, position 74.

Source Error:


Line 51: <!-- Example: <add key="settingName" value="settingValue"/> -->
Line 52: <add key="Session["ConnStr"].ToString ()" value="" />
Line 53: <add key="Constr" value="data source=192.168.1.106;user id=sa;password=";>
Line 54: </appSettings>
Line 55: </configuration>


Source File: C:\Inetpub\wwwroot\SqlEntManager\web.config Line: 53
为什么还有这个错误?
xj1122 2004-03-29
  • 打赏
  • 举报
回复
来晚了~
wudixiaocaoren 2004-03-29
  • 打赏
  • 举报
回复
阿枫正解,楼主根本就没设置!
qynum123 2004-03-29
  • 打赏
  • 举报
回复
jiangchuandong 2004-03-29
  • 打赏
  • 举报
回复
程序的代码是在
URL http://heanet.dl.sourceforge.net/sourceforge/asp-ent-man/SqlEntManager.zip
程序的是类似于phpadmin的b/ssqlserver管理器
简介
http://sourceforge.net/projects/asp-ent-man/
摘要:
ASP.NET Enterprise Manager is a web based version of the application that is provided with SQL Server. Inspired by the functionality of PHP MyAdmin, this project attempts to give SQL Server and MSDE database users a web based administration and developm


:Database Foundry, Distributed Computing Foundry


Development Status: 2 - Pre-Alpha, 3 - Alpha

Environment: Web Environment

Intended Audience: Developers, End Users/Desktop, System Administrators

License: GNU General Public License (GPL)

Natural Language: English

Operating System: Windows NT/2000

Programming Language: ASP, C#, Visual Basic

Topic: Front-Ends
jiangchuandong 2004-03-29
  • 打赏
  • 举报
回复
to:
barrytam(=阿楼=(ASP.Net Times))
我肯定192.168.1.106这台有sa这个用户的
to:
xunjie(xunjie)
using System.Configuration;这个类,我下载的程序是没有引用,一定要引用吗?

大家都叫我帖出主要连接函数,这样写的
public SqlDBHandler (string DataSource, string Catalog, string UserName, string Password)
{
m_DataSource = DataSource;
m_Catalog = Catalog;
m_UserName = UserName;
m_Password = Password;

m_ConnStr = "server=" + m_DataSource + ";database=" + m_Catalog + ";uid=" + m_UserName + ";pwd=" + m_Password + ";";

m_conn = new SqlConnection (m_ConnStr);
}
xunjie 2004-03-29
  • 打赏
  • 举报
回复
xunjie(xunjie) 补充:
还要导入命名空间:
using System.Data.SqlClient;
using System.Configuration;
Seeko0 2004-03-29
  • 打赏
  • 举报
回复
在其它页面要用到数据库连接时这样写:


SqlConnection cn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings
["Constr"]);
注意区分大小写
xunjie 2004-03-29
  • 打赏
  • 举报
回复
<configuration>
<appSettings>
<add key="Constr" value="server=数据库服务器IP;user id=sa;password=密码;DataBase=数据库名">
</appSettings>
例如:
<appSettings>
<add key="Constr" value="server=192.168.10.55;user id=sa;password=shumi;DataBase=news">
</appSettings>
</configuration>


在其它页面要用到数据库连接时这样写:
SqlConnection cn=new SqlConnection(ConfigurationSettings.AaaSettings["Constr"]);
注意区分大小写

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧