连接到外部SQL数据库

时间:2016-08-01 16:07:20

标签: c# sql-server visual-studio wcf

我正在编写Windows 10桌面应用程序(UWP C#)

我尝试访问数据库。

我读到我无法直接执行此操作,但我可以使用WCF

执行此操作

我添加了WCF服务并添加了此代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCFtoDB
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService
    {

        [OperationContract]
        DataSet querySql();
    }
    public class Service : IService
    {
        /// <summary> 
        /// Запрос данных в TestTable 
        /// </summary> 
        /// <returns></returns> 

        SqlConnection sqlCon = new SqlConnection("Data Source=(local);Initial Catalog=Test;Integrated Security =SSPI;");
        public DataSet querySql()
        {
            try
            {
                sqlCon.Open();
                string strSql = "select Title, Text from TestTable";
                DataSet ds = new DataSet();
                SqlDataAdapter sqlDa = new SqlDataAdapter(strSql, sqlCon);
                sqlDa.Fill(ds);
                return ds;
            }
            finally
            {
                sqlCon.Close();
            }
        }
    }

我的SQL数据库位于此地址(144.76.133.122

我需要在哪里写这个地址?

我是否需要在BD上有桌子或没有?

0 个答案:

没有答案
相关问题