仍然我的问题不是解决连接字符串问题 [英] Still my issues is not solve connection string issues

查看:55
本文介绍了仍然我的问题不是解决连接字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Visual Studio 2008和SL Server 2008 Web应用程序.

在web.config中,我给出了连接字符串

Hi
i am using visual studio 2008 and sl server 2008 web application.

in web.config i have given connection string

<connectionStrings>
		<add name="ApplicationServices" connectionString="data source= midas Host;Integrated Security=SSPI;intial catalog=kandivalideal;User Instance=true" providerName="System.Data.SqlClient"/>
	</connectionStrings>




然后我尝试在默认页面上调用连接字符串




and then i am trying to call the connection string on default page

SqlConnection cnn = new SqlConnection();
        cnn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
        cnn.Open(); 
        SqlCommand cmd = new SqlCommand("select mobileno, password from register where mobileno=''" + txtmobile.Text + "''and password=''" + txtpassword.Text + "''", cnn);
        cmd.Connection = cnn;
        SqlDataReader dr = cmd.ExecuteReader();





建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接.





A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


谁能告诉我问题是什么?


can any one tell me what is the issues

推荐答案

尝试一下,
C#

Try this,
C#

SqlConnection cnn = new SqlConnection();
        string sqlcon = System.Configuration.ConfigurationManager.AppSettings["connString"];
        cnn = new SqlConnection(sqlcon);
        cnn.Open();
        SqlCommand cmd = new SqlCommand("select mobileno, password from register where mobileno='" + txtmobile.Text + "'and password='" + txtpassword.Text + "'", cnn);
        cmd.Connection = cnn;
        SqlDataReader dr = cmd.ExecuteReader();



web.config



web.config

<appsettings>
<add key="connString" value="server=midas Host;database=kandivalideal;" />
</appsettings>


我认为您错过了命名空间系统.Configuration [^ ]
I think you missed the namespace System.Configuration[^]


通过单击Project->添加对System.Configuration的引用.添加参考...并在.NET组件中搜索System.Configuration
添加名称空间System.Configuration.
Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration
add namespace System.Configuration.


这篇关于仍然我的问题不是解决连接字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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