Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
769 views
in Technique[技术] by (71.8m points)

c# - SQL Server connection string

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.56SERVER_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;";  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...