如何使应用程序使用数据库sql server? [英] How to make a application use database sql server ?
本文介绍了如何使应用程序使用数据库sql server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试制作一个与数据库SQL Server交互的简单应用程序,并且它可以在LAN上运行.我的想法是通过更改连接字符串来使用远程连接,例如:
Hello everybody ,
I am trying to make a simple application that interact to database SQL server, and it can run over a LAN. My ideas is use remote Connection by changing the Connection String like:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// string strcon = ConfigurationManager.ConnectionStrings["strcon"].ConnectionString;
string strcon="Data Source=192.168.1.36,1433;Network Library=DBMSSOCN;Initial Catalog=TracNghiem;Integrated Security=true;";
// string strcon = "Server=.\\SQLEXPRESS;Database=TracNghiem;Integrated Security=true;";
SqlConnection con;
try
{
con = new SqlConnection(strcon);
con.Open();
MessageBox.Show("Connected Successfully");
}
catch(Exception xe)
{
MessageBox.Show("Error\n" + xe.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
但是我可以成功运行它!我的问题:可能吗?以及为什么我不能运行它!
感谢您的阅读!
But I can run it successfully! My question : Is it possible ? And why I cann''t run it !
Thanks for reading !
推荐答案
您和所有用户都位于同一个域中吗?您的问题/错误消息是什么?
我以前使用logmein从另一个国家/地区进行设置.我建议您在每台计算机上设置DSN并确保测试连接.
Will you and all users be on the same domain? What is your problem / error message?
I have set this up from another country using logmein free before. I would suggest that you setup DSN on each machine and make sure you test the connection.
也可以访问connectionstrings网站
Also visit connectionstrings website
这篇关于如何使应用程序使用数据库sql server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文