如何使用Sql ServerAuthentication连接到数据库 [英] How do I connect to a database with Sql ServerAuthentication

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

问题描述

我无法连接到数据库。任何人都可以帮忙吗?直到现在我已经完成了:

I am unable to connect to the database. Can any one please help? Till now I have done:

protected void Page_Load(object sender, EventArgs e) 
{ 
SqlConnection sqlobj = new SqlConnection("Data Source = 182.18.175.64 ; Initial Catalog = TamilnaduForestDept ; Login = ***** ; Password = *****; Integrated Security = True");
string sel = "select Status_CommonID,Status_CommonName,Active_Status,EntryBy,EntryDate from Mst_Status_Common"; 
sqlobj.Open(); 
SqlDataAdapter adp = new SqlDataAdapter(sel, sqlobj); 
DataSet ds = new DataSet(); 
adp.Fill(ds); 
for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
{ 
ddl_StatusCommon.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
 } 
} 
protected void ddl_StatusCommon_SelectedIndexChanged(object sender, EventArgs e) 
{ 
SqlConnection sqlobj = new SqlConnection("Data Source = 182.18.175.64 ; Initial Catalog = TamilnaduForestDept ; Login = ******; Password = *****; Integrated Security = True"); 
string sel = "select Status_CommonId,Status_CommonName,Active_Status,EntryBy,EntryDate from office where Status_CommonId = '" + ddl_StatusCommon.SelectedItem.ToString() + "'"; sqlobj.Open(); 
SqlDataAdapter adp = new SqlDataAdapter(sel, sqlobj); 
DataSet ds = new DataSet(); 
adp.Fill(ds); 
for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
{ 
ddl_StatusCommon.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
 } 
}

推荐答案

首先通过SSMS对您的连接进行排序:这样您就可以确保拥有在您转移到自己的代码之前,您的来源,用户名和密码是正确的,其中存在其他潜在问题。当你转移到代码时,不要硬编码你的连接字符串!它需要在一些描述的配置文件中,因为它会改变 - 然后你必须重新编译并重新发布你的源代码...



所以,在SSMS或Visual Studio中尝试,如果它不起作用,请开始查看错误消息以解释原因。
使用Visual Studio进行的快速测试表明存在一个SQL Server实例那个IP地址,但我尝试的用户名和密码不起作用 - 可以预见的,因为我不了解它们,我很高兴地说管理员已经更改了默认的超级用户登录!



最好的猜测是你的用户名和密码错了......
Get your connection sorted via SSMS first: that way you can ensure that you have your source, username and password correct before your move to your own code where there are other potential problems. And when you do move to code, don't hard-code your connection string! It needs to be in a configuration file of some description, because it will change - and then you have to recompile and re-issue your source code...

So, try it in SSMS or Visual Studio, and if it doesn't work, start looking at the error message to explain why not.
A quick test with Visual Studio says there is an SQL Server Instance at that IP address, but that the username and Password I tried did not work - predictably enough, because I don't know them and I'm glad to say the admin has changed the default superuser login!

The best guess is that your Username and Password are wrong...


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

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