Localhost连接数据库的问题 [英] Localhost connecting database problem

查看:243
本文介绍了Localhost连接数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net,C#,VS 2005和sql server 2005

我已经为我的Web项目创建了一个安装文件...

我也在PC上安装了IIS.
我已经安装了我的项目...

我的web.config包含以下连接字符串:

 <  配置 > ; 
    <   appSettings/ > 
    <   connectionStrings  > 
        <  添加    ="   conStr"  connectionString    Server = localhost ; Database = MYDB; Trusted_Connection =是;"  providerName    System.Data.SqlClient" > 
       
    <  /connectionStrings  > 
    <   system.web  > 
        <!-  
            将编译设置为debug ="true"以插入调试
            符号插入已编译的页面.因为这
            影响性能,将此值仅设置为true
            在开发过程中.
         ->  
        <  编译    ="   true"  defaultLanguage    c#" >  



但是当我键入http://localhost/WebSetup1/Firstpage.aspx

它将显示一个页面..

但是当我单击包含与数据库的连接的页面时,它没有显示或执行..

当我单击插入按钮时,它将给出错误消息,例如对象引用未设置为对象的实例...

总之:未建立数据库连接.

有什么问题..

任何解决方案请..

问候
karan

解决方案

在连接字符串中提供UID和密码

[ DATASOURCE = localhost; UID = sa; PWD =; DATABASE = test ]

在IIS上部署代码时,它是否运行?
您的SQL是否已安装在同一台计算机上?


使用此连接字符串:

数据源=本地主机;初始目录= MYDB;集成安全性= SSPI;"安全性= true或Trusted_connection


< connectionstrings>
< add name ="conStr" connectionstring ="Server = localhost; Database = MYDB; User ID = sa; Password = abc" providername ="System.Data.SqlClient">


i am using asp.net,C#,VS 2005,and sql server 2005

i have created a setup file for my web project...

i have also installed IIS in my PC..

i have installed my project ...

my web.config contains the following connection string:

<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="conStr" connectionString="Server=localhost;Database=MYDB;Trusted_Connection=Yes;" providerName="System.Data.SqlClient"/>
       
    </connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true" defaultLanguage="c#">



but when i type http://localhost/WebSetup1/Firstpage.aspx

it will display a page..

but when i click on page that contains connection with the database it is not shown or executed..

it will give error message like object reference not set to an instance of an object when i do click on insert button...

In short : database connection is not established..

what is the problem..

any solution please..

regards
karan

解决方案

Give UID and Password in your connection string

[DATASOURCE=localhost;UID=sa;PWD=;DATABASE=test]

when you deploy your code on IIS did it run ?
have your SQL installed on same machine ?


use this Connection String:

"Data Source=localhost;Initial Catalog=MYDB;Integrated Security=SSPI;"


I you have placed website in IIS then you need to pass userid and password in connection string in place of integrated security =true or trusted_connection


<connectionstrings>
<add name="conStr" connectionstring="Server=localhost;Database=MYDB;User ID=sa; Password=abc" providername="System.Data.SqlClient">


这篇关于Localhost连接数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆