Visual Web部件,无法连接到数据库 [英] Visual Web part, Unable to connect to Database

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

问题描述

我正在为SharePoint 2013编写Visual Webpart,它将部署在SharePoint页面上.

I am writing Visual webpart for SharePoint 2013 which will get deployed on SharePoint page.

我已经编写了从Web部件中的SQL Server获取数据的代码.

I have written the code to get data from SQL server in the web part.

但是,从此代码连接到数据库时,我遇到了问题.我由于无法连接数据库而出现异常,有时,用户XXXX的连接登录失败".

However, I am facing the issue while connection to database from this code. I am getting exception as Unable to Connect to database and some times, "Connection Login failed for user XXXX".

在SQL Server上具有足够权限的用户ID.

The user id having enough permission on SQL server.

当我从简单的控制台应用程序运行相同的代码时,它工作正常.

When I run the same code from simple console application, it works fine. 

这是我的代码:

con.ConnectionString = @"数据源= XXXXXXX \ SHAREPOINT;初始目录=示例;集成安全性= True;
                    con.Open();
                   字符串查询=从样本中选择*,其中名称='" +名字+'''和Surname ='" + lastName +"'" ;;
                    //SqlCommand命令=新的SqlCommand(query);
                    SqlDataAdapter sqladapter =新的SqlDataAdapter(query,con);
                    sqladapter.Fill(dt);
                    con.Close();

 con.ConnectionString = @"Data Source=XXXXXXX\SHAREPOINT;Initial Catalog=Sample;Integrated Security=True";
                    con.Open();
                    string query = "Select * from Sample where Name = '" + firstName +"' and Surname = '"+lastName+"'";
                    //SqlCommand command = new SqlCommand(query);
                    SqlDataAdapter sqladapter = new SqlDataAdapter(query,con);
                    sqladapter.Fill(dt);
                    con.Close();

我什至尝试在连接字符串中使用用户ID和密码,但是没有运气.

I even tried with User Id and password in the connection string but no luck.

这是由于SharePoint而引起的,无法理解.任何帮助,将不胜感激.

is this is due to the SharePoint, Not able to understand. any help on this will be appreciated.

谢谢

Ganesh

推荐答案

与SharePoint无关.

It has nothing to do with SharePoint.

运行测试应用程序的服务器是否与SharePoint Server相同?

Is the server running your test application same as SharePoint Server?


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

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