SQL Server connection string

耗尽温柔 提交于 2019-11-28 08:16:57

问题


I'm guessing you get hundreds of these questions, but here goes:

So I'm trying to get a Honeywell Dolphin 6100 mobile device (CE5.0, .NET Compact Framework) to talk to an SQL Server Express 2008 database installed on the machine I'm developing on.

I am a complete newbie to SQL Server and mobile development, and am still a little green in C# (yeah I know, jumped in the deep end here, eh? :D)

So far I have:

string sConnection = @"Data Source=JEZ-LAPTOP;DataBase=EMS_Main;Integrated Security=SSPI;";   
SqlConnection sqc = new SqlConnection(sConnection);
sqc.Open();

The app deploys quite happily to the 6100, but the last line bugs out with a vague "SQL Exception" error.

I have tried changing the Data Source to include instance names, slashes and dots before it etc etc (even though server is just using the default instance), to no avail.

I can connect to the database in Management Studio with no problems.

So, is the connection string at fault, or is it something I haven't done correctly in SQL Server?

Thanks in advance.

This site is awesome btw, some very knowledgable guys here.


回答1:


CE 5.0 does not support integrated security. I believe the first version to support it was mobile 6.1. In any case, you cannot use SSPI with your configuration. You'll have to create a SQL Server user and use that as your connection credentials.

Another thing to try, besides using a UID/PWD to connect is to refer to the server by IP. It's possible that DNS resolution is not taking place properly on your device. Hmm, that is a whole nother issue. Is your device on the same network as the SQL Server?

And for future reference, commit this handy URL to memory: http://connectionstrings.com

EDIT

Let's see something like... if Named SQL Server instance:

@"Data Source=192.168.0.56\SERVER_NAME;DataBase=EMS_Main;User Id=joe;Password=pwd;";

if not named SQL Server instance:

@"Data Source=192.168.0.56;DataBase=EMS_Main;User Id=joe;Password=pwd;";  


来源:https://stackoverflow.com/questions/4819818/sql-server-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!